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);
393 * create devices. dev_ops_add() must be called to make devices under
394 * this major number available to userland.
396 dev_ops_add(&sc_ops, ~(MAXCONS - 1), unit * MAXCONS);
398 for (vc = 1; vc < sc->vtys; vc++) { //XXX: possibly breaks something, or even a lot
399 dev = make_dev(&sc_ops, vc + unit * MAXCONS,
400 UID_ROOT, GID_WHEEL, 0600, "ttyv%r", vc + unit * MAXCONS);
403 * The first vty already has struct tty and scr_stat initialized
404 * in scinit(). The other vtys will have these structs when
409 dev_ops_add(&sc_ops, -1, SC_CONSOLECTL); /* XXX */
410 cctl_dev = make_dev(&sc_ops, SC_CONSOLECTL,
411 UID_ROOT, GID_WHEEL, 0600, "consolectl");
412 cctl_dev->si_tty = sc_console_tty = ttymalloc(sc_console_tty);
413 cctl_dev->si_drv1 = sc_console;
425 * As soon as malloc() becomes functional, we had better allocate
426 * various buffers for the kernel console.
429 if (sc_console_unit < 0) /* sc_console == NULL */
432 /* copy the temporary buffer to the final buffer */
433 sc_alloc_scr_buffer(sc_console, TRUE, FALSE);
435 #ifndef SC_NO_CUTPASTE
436 sc_alloc_cut_buffer(sc_console, TRUE);
439 #ifndef SC_NO_HISTORY
440 /* initialize history buffer & pointers */
441 sc_alloc_history_buffer(sc_console, 0, 0, TRUE);
445 SYSINIT(sc_mem, SI_BOOT1_POST, SI_ORDER_ANY, scmeminit, NULL);
448 scdevtounit(cdev_t dev)
450 int vty = SC_VTY(dev);
452 if (vty == SC_CONSOLECTL)
453 return ((sc_console != NULL) ? sc_console->sc->unit : -1);
454 else if ((vty < 0) || (vty >= MAXCONS*sc_max_unit()))
461 scopen(struct dev_open_args *ap)
463 cdev_t dev = ap->a_head.a_dev;
464 int unit = scdevtounit(dev);
471 DPRINTF(5, ("scopen: dev:%d,%d, unit:%d, vty:%d\n",
472 major(dev), minor(dev), unit, SC_VTY(dev)));
474 sc = sc_get_softc(unit, (sc_console_unit == unit) ? SC_KERNEL_CONSOLE : 0);
478 tp = dev->si_tty = ttymalloc(dev->si_tty);
479 tp->t_oproc = scstart;
480 tp->t_param = scparam;
481 tp->t_stop = nottystop;
485 if (!ISTTYOPEN(tp)) {
487 /* Use the current setting of the <-- key as default VERASE. */
488 /* If the Delete key is preferable, an stty is necessary */
489 if (sc->kbd != NULL) {
490 key.keynum = KEYCODE_BS;
491 kbd_ioctl(sc->kbd, GIO_KEYMAPENT, (caddr_t)&key);
492 tp->t_cc[VERASE] = key.key.map[0];
494 tp->t_iflag = TTYDEF_IFLAG;
495 tp->t_oflag = TTYDEF_OFLAG;
496 tp->t_cflag = TTYDEF_CFLAG;
497 tp->t_lflag = TTYDEF_LFLAG;
498 tp->t_ispeed = tp->t_ospeed = TTYDEF_SPEED;
499 scparam(tp, &tp->t_termios);
500 (*linesw[tp->t_line].l_modem)(tp, 1);
503 if (tp->t_state & TS_XCLUDE && priv_check_cred(ap->a_cred, PRIV_ROOT, 0))
506 error = (*linesw[tp->t_line].l_open)(dev, tp);
510 scp = dev->si_drv1 = alloc_scp(sc, SC_VTY(dev));
512 sc_set_pixel_mode(scp, NULL, COL, ROW, 16);
514 if (!tp->t_winsize.ws_col && !tp->t_winsize.ws_row) {
515 tp->t_winsize.ws_col = scp->xsize;
516 tp->t_winsize.ws_row = scp->ysize;
523 scclose(struct dev_close_args *ap)
525 cdev_t dev = ap->a_head.a_dev;
526 struct tty *tp = dev->si_tty;
530 if (SC_VTY(dev) != SC_CONSOLECTL) {
531 scp = SC_STAT(tp->t_dev);
532 /* were we in the middle of the VT switching process? */
533 DPRINTF(5, ("sc%d: scclose(), ", scp->sc->unit));
534 if ((scp == scp->sc->cur_scp) && (scp->sc->unit == sc_console_unit))
535 cons_unavail = FALSE;
537 * note: must be called from a critical section because finish_vt_rel
538 * will call do_switch_scr which releases it temporarily
540 if (finish_vt_rel(scp, TRUE) == 0) /* force release */
541 DPRINTF(5, ("reset WAIT_REL, "));
542 if (finish_vt_acq(scp) == 0) /* force acknowledge */
543 DPRINTF(5, ("reset WAIT_ACQ, "));
545 if (scp == &main_console) {
548 scp->smode.mode = VT_AUTO;
551 sc_vtb_destroy(&scp->vtb);
552 sc_vtb_destroy(&scp->scr);
553 sc_free_history_buffer(scp, scp->ysize);
555 kfree(scp, M_SYSCONS);
560 scp->smode.mode = VT_AUTO;
562 scp->kbd_mode = K_XLATE;
563 if (scp == scp->sc->cur_scp)
564 kbd_ioctl(scp->sc->kbd, KDSKBMODE, (caddr_t)&scp->kbd_mode);
565 DPRINTF(5, ("done.\n"));
567 (*linesw[tp->t_line].l_close)(tp, ap->a_fflag);
575 scread(struct dev_read_args *ap)
577 sc_touch_scrn_saver();
578 return (ttyread(ap));
582 sckbdevent(keyboard_t *thiskbd, int event, void *arg)
591 * WARNING: In early boot sc->dev may not be setup yet.
593 sc = (sc_softc_t *)arg;
594 /* assert(thiskbd == sc->kbd) */
599 case KBDIO_UNLOADING:
602 kbd_release(thiskbd, (void *)&sc->keyboard);
609 * Loop while there is still input to get from the keyboard.
610 * I don't think this is nessesary, and it doesn't fix
611 * the Xaccel-2.1 keyboard hang, but it can't hurt. XXX
613 while ((c = scgetc(sc, SCGETC_NONBLOCK)) != NOKEY) {
614 cur_tty = VIRTUAL_TTY(sc, sc->cur_scp->index);
615 if (!ISTTYOPEN(cur_tty)) {
616 cur_tty = sc_console_tty;
617 if (!ISTTYOPEN(cur_tty))
621 if ((*sc->cur_scp->tsw->te_input)(sc->cur_scp, c, cur_tty))
624 switch (KEYFLAGS(c)) {
625 case 0x0000: /* normal key */
626 (*linesw[cur_tty->t_line].l_rint)(KEYCHAR(c), cur_tty);
628 case FKEY: /* function key, return string */
629 cp = kbd_get_fkeystr(thiskbd, KEYCHAR(c), &len);
632 (*linesw[cur_tty->t_line].l_rint)(*cp++, cur_tty);
635 case MKEY: /* meta is active, prepend ESC */
636 (*linesw[cur_tty->t_line].l_rint)(0x1b, cur_tty);
637 (*linesw[cur_tty->t_line].l_rint)(KEYCHAR(c), cur_tty);
639 case BKEY: /* backtab fixed sequence (esc [ Z) */
640 (*linesw[cur_tty->t_line].l_rint)(0x1b, cur_tty);
641 (*linesw[cur_tty->t_line].l_rint)('[', cur_tty);
642 (*linesw[cur_tty->t_line].l_rint)('Z', cur_tty);
647 sc->cur_scp->status |= MOUSE_HIDDEN;
653 scparam(struct tty *tp, struct termios *t)
655 tp->t_ispeed = t->c_ispeed;
656 tp->t_ospeed = t->c_ospeed;
657 tp->t_cflag = t->c_cflag;
662 scioctl(struct dev_ioctl_args *ap)
664 cdev_t dev = ap->a_head.a_dev;
665 u_long cmd = ap->a_cmd;
666 caddr_t data = ap->a_data;
667 int flag = ap->a_fflag;
676 error = sc_vid_ioctl(tp, cmd, data, flag);
677 if (error != ENOIOCTL)
680 #ifndef SC_NO_HISTORY
681 error = sc_hist_ioctl(tp, cmd, data, flag);
682 if (error != ENOIOCTL)
686 #ifndef SC_NO_SYSMOUSE
687 error = sc_mouse_ioctl(tp, cmd, data, flag);
688 if (error != ENOIOCTL)
692 scp = SC_STAT(tp->t_dev);
693 /* assert(scp != NULL) */
694 /* scp is sc_console, if SC_VTY(dev) == SC_CONSOLECTL. */
698 error = (*scp->tsw->te_ioctl)(scp, tp, cmd, data, flag);
699 if (error != ENOIOCTL)
703 switch (cmd) { /* process console hardware related ioctl's */
705 case GIO_ATTR: /* get current attributes */
706 /* this ioctl is not processed here, but in the terminal emulator */
709 case GIO_COLOR: /* is this a color console ? */
710 *(int *)data = (sc->adp->va_flags & V_ADP_COLOR) ? 1 : 0;
713 case CONS_BLANKTIME: /* set screen saver timeout (0 = no saver) */
714 if (*(int *)data < 0 || *(int *)data > MAX_BLANKTIME)
717 scrn_blank_time = *(int *)data;
718 run_scrn_saver = (scrn_blank_time != 0);
722 case CONS_CURSORTYPE: /* set cursor type blink/noblink */
724 if (!ISGRAPHSC(sc->cur_scp))
725 sc_remove_cursor_image(sc->cur_scp);
726 if ((*(int*)data) & 0x01)
727 sc->flags |= SC_BLINK_CURSOR;
729 sc->flags &= ~SC_BLINK_CURSOR;
730 if ((*(int*)data) & 0x02) {
731 sc->flags |= SC_CHAR_CURSOR;
733 sc->flags &= ~SC_CHAR_CURSOR;
735 * The cursor shape is global property; all virtual consoles
736 * are affected. Update the cursor in the current console...
738 if (!ISGRAPHSC(sc->cur_scp)) {
739 sc_set_cursor_image(sc->cur_scp);
740 sc_draw_cursor_image(sc->cur_scp);
745 case CONS_BELLTYPE: /* set bell type sound/visual */
746 if ((*(int *)data) & 0x01)
747 sc->flags |= SC_VISUAL_BELL;
749 sc->flags &= ~SC_VISUAL_BELL;
750 if ((*(int *)data) & 0x02)
751 sc->flags |= SC_QUIET_BELL;
753 sc->flags &= ~SC_QUIET_BELL;
756 case CONS_GETINFO: /* get current (virtual) console info */
758 vid_info_t *ptr = (vid_info_t*)data;
759 if (ptr->size == sizeof(struct vid_info)) {
760 ptr->m_num = sc->cur_scp->index;
761 ptr->font_size = scp->font_size;
762 ptr->mv_col = scp->xpos;
763 ptr->mv_row = scp->ypos;
764 ptr->mv_csz = scp->xsize;
765 ptr->mv_rsz = scp->ysize;
767 * The following fields are filled by the terminal emulator. XXX
774 ptr->mv_grfc.fore = 0; /* not supported */
775 ptr->mv_grfc.back = 0; /* not supported */
776 ptr->mv_ovscan = scp->border;
777 if (scp == sc->cur_scp)
779 ptr->mk_keylock = scp->status & LOCK_MASK;
785 case CONS_GETVERS: /* get version number */
786 *(int*)data = 0x200; /* version 2.0 */
789 case CONS_IDLE: /* see if the screen has been idle */
791 * When the screen is in the GRAPHICS_MODE or UNKNOWN_MODE,
792 * the user process may have been writing something on the
793 * screen and syscons is not aware of it. Declare the screen
794 * is NOT idle if it is in one of these modes. But there is
795 * an exception to it; if a screen saver is running in the
796 * graphics mode in the current screen, we should say that the
797 * screen has been idle.
799 *(int *)data = (sc->flags & SC_SCRN_IDLE)
800 && (!ISGRAPHSC(sc->cur_scp)
801 || (sc->cur_scp->status & SAVER_RUNNING));
804 case CONS_SAVERMODE: /* set saver mode */
805 switch(*(int *)data) {
808 /* if a LKM screen saver is running, stop it first. */
809 scsplash_stick(FALSE);
810 saver_mode = *(int *)data;
813 if ((error = wait_scrn_saver_stop(NULL))) {
818 run_scrn_saver = TRUE;
819 if (saver_mode == CONS_USR_SAVER)
820 scp->status |= SAVER_RUNNING;
822 scp->status &= ~SAVER_RUNNING;
823 scsplash_stick(TRUE);
828 if ((saver_mode == CONS_USR_SAVER) && (scp->status & SAVER_RUNNING))
829 scp->status &= ~SAVER_RUNNING;
830 saver_mode = *(int *)data;
838 case CONS_SAVERSTART: /* immediately start/stop the screen saver */
840 * Note that this ioctl does not guarantee the screen saver
841 * actually starts or stops. It merely attempts to do so...
844 run_scrn_saver = (*(int *)data != 0);
846 sc->scrn_time_stamp -= scrn_blank_time;
850 case CONS_SCRSHOT: /* get a screen shot */
852 scrshot_t *ptr = (scrshot_t*)data;
854 if (ISGRAPHSC(scp)) {
858 if (scp->xsize != ptr->xsize || scp->ysize != ptr->ysize) {
862 copyout ((void*)scp->vtb.vtb_buffer, ptr->buf,
863 ptr->xsize * ptr->ysize * sizeof(uint16_t));
868 case VT_SETMODE: /* set screen switcher mode */
870 struct vt_mode *mode;
872 mode = (struct vt_mode *)data;
873 DPRINTF(5, ("sc%d: VT_SETMODE ", sc->unit));
874 if (scp->smode.mode == VT_PROCESS) {
875 if (scp->proc == pfind(scp->pid) && scp->proc != curproc) {
876 DPRINTF(5, ("error EPERM\n"));
881 if (mode->mode == VT_AUTO) {
882 scp->smode.mode = VT_AUTO;
885 DPRINTF(5, ("VT_AUTO, "));
886 if ((scp == sc->cur_scp) && (sc->unit == sc_console_unit))
887 cons_unavail = FALSE;
889 * note: must be called from a critical section because
890 * finish_vt_rel will call do_switch_scr which releases it
893 if (finish_vt_rel(scp, TRUE) == 0)
894 DPRINTF(5, ("reset WAIT_REL, "));
895 if (finish_vt_acq(scp) == 0)
896 DPRINTF(5, ("reset WAIT_ACQ, "));
898 if (!ISSIGVALID(mode->relsig) || !ISSIGVALID(mode->acqsig)
899 || !ISSIGVALID(mode->frsig)) {
901 DPRINTF(5, ("error EINVAL\n"));
904 DPRINTF(5, ("VT_PROCESS %d, ", curproc->p_pid));
905 bcopy(data, &scp->smode, sizeof(struct vt_mode));
907 scp->pid = scp->proc->p_pid;
908 if ((scp == sc->cur_scp) && (sc->unit == sc_console_unit))
916 case VT_GETMODE: /* get screen switcher mode */
917 bcopy(&scp->smode, data, sizeof(struct vt_mode));
920 case VT_RELDISP: /* screen switcher ioctl */
923 * This must be the current vty which is in the VT_PROCESS
926 if ((scp != sc->cur_scp) || (scp->smode.mode != VT_PROCESS)) {
930 /* ...and this process is controlling it. */
931 if (scp->proc != curproc) {
936 switch(*(int *)data) {
937 case VT_FALSE: /* user refuses to release screen, abort */
939 * note: must be called from a critical section because
940 * finish_vt_rel will call do_switch_scr which releases it
943 if ((error = finish_vt_rel(scp, FALSE)) == 0)
944 DPRINTF(5, ("sc%d: VT_FALSE\n", sc->unit));
946 case VT_TRUE: /* user has released screen, go on */
948 * note: must be called from a critical section because
949 * finish_vt_rel will call do_switch_scr which releases it
952 if ((error = finish_vt_rel(scp, TRUE)) == 0)
953 DPRINTF(5, ("sc%d: VT_TRUE\n", sc->unit));
955 case VT_ACKACQ: /* acquire acknowledged, switch completed */
956 if ((error = finish_vt_acq(scp)) == 0)
957 DPRINTF(5, ("sc%d: VT_ACKACQ\n", sc->unit));
965 case VT_OPENQRY: /* return free virtual console */
966 for (i = sc->first_vty; i < sc->first_vty + sc->vtys; i++) {
967 tp = VIRTUAL_TTY(sc, i);
968 if (!ISTTYOPEN(tp)) {
969 *(int *)data = i + 1;
975 case VT_ACTIVATE: /* switch to screen *data */
976 i = (*(int *)data == 0) ? scp->index : (*(int *)data - 1);
978 sc_clean_up(sc->cur_scp);
980 return sc_switch_scr(sc, i);
982 case VT_WAITACTIVE: /* wait for switch to occur */
983 i = (*(int *)data == 0) ? scp->index : (*(int *)data - 1);
984 if ((i < sc->first_vty) || (i >= sc->first_vty + sc->vtys))
987 error = sc_clean_up(sc->cur_scp);
991 scp = SC_STAT(SC_DEV(sc, i));
992 if (scp == scp->sc->cur_scp)
994 error = tsleep((caddr_t)&scp->smode, PCATCH, "waitvt", 0);
995 /* May return ERESTART */
998 case VT_GETACTIVE: /* get active vty # */
999 *(int *)data = sc->cur_scp->index + 1;
1002 case VT_GETINDEX: /* get this vty # */
1003 *(int *)data = scp->index + 1;
1006 case VT_LOCKSWITCH: /* prevent vty switching */
1007 if ((*(int *)data) & 0x01)
1008 sc->flags |= SC_SCRN_VTYLOCK;
1010 sc->flags &= ~SC_SCRN_VTYLOCK;
1013 case KDENABIO: /* allow io operations */
1014 error = priv_check_cred(ap->a_cred, PRIV_ROOT, 0);
1017 if (securelevel > 0)
1019 #if defined(__i386__)
1020 curthread->td_lwp->lwp_md.md_regs->tf_eflags |= PSL_IOPL;
1021 #elif defined(__amd64__)
1022 curthread->td_lwp->lwp_md.md_regs->tf_rflags |= PSL_IOPL;
1026 case KDDISABIO: /* disallow io operations (default) */
1027 #if defined(__i386__)
1028 curthread->td_lwp->lwp_md.md_regs->tf_eflags &= ~PSL_IOPL;
1029 #elif defined(__amd64__)
1030 curthread->td_lwp->lwp_md.md_regs->tf_rflags &= ~PSL_IOPL;
1034 case KDSKBSTATE: /* set keyboard state (locks) */
1035 if (*(int *)data & ~LOCK_MASK)
1037 scp->status &= ~LOCK_MASK;
1038 scp->status |= *(int *)data;
1039 if (scp == sc->cur_scp)
1040 update_kbd_state(scp, scp->status, LOCK_MASK);
1043 case KDGKBSTATE: /* get keyboard state (locks) */
1044 if (scp == sc->cur_scp)
1045 save_kbd_state(scp);
1046 *(int *)data = scp->status & LOCK_MASK;
1049 case KDGETREPEAT: /* get keyboard repeat & delay rates */
1050 case KDSETREPEAT: /* set keyboard repeat & delay rates (new) */
1051 error = kbd_ioctl(sc->kbd, cmd, data);
1052 if (error == ENOIOCTL)
1056 case KDSETRAD: /* set keyboard repeat & delay rates (old) */
1057 if (*(int *)data & ~0x7f)
1059 error = kbd_ioctl(sc->kbd, cmd, data);
1060 if (error == ENOIOCTL)
1064 case KDSKBMODE: /* set keyboard mode */
1065 switch (*(int *)data) {
1066 case K_XLATE: /* switch to XLT ascii mode */
1067 case K_RAW: /* switch to RAW scancode mode */
1068 case K_CODE: /* switch to CODE mode */
1069 scp->kbd_mode = *(int *)data;
1070 if (scp == sc->cur_scp)
1071 kbd_ioctl(sc->kbd, cmd, data);
1078 case KDGKBMODE: /* get keyboard mode */
1079 *(int *)data = scp->kbd_mode;
1083 error = kbd_ioctl(sc->kbd, cmd, data);
1084 if (error == ENOIOCTL)
1088 case KDMKTONE: /* sound the bell */
1090 sc_bell(scp, (*(int*)data)&0xffff,
1091 (((*(int*)data)>>16)&0xffff)*hz/1000);
1093 sc_bell(scp, scp->bell_pitch, scp->bell_duration);
1096 case KIOCSOUND: /* make tone (*data) hz */
1097 if (scp == sc->cur_scp) {
1099 return sc_tone(*(int *)data);
1105 case KDGKBTYPE: /* get keyboard type */
1106 error = kbd_ioctl(sc->kbd, cmd, data);
1107 if (error == ENOIOCTL) {
1108 /* always return something? XXX */
1113 case KDSETLED: /* set keyboard LED status */
1114 if (*(int *)data & ~LED_MASK) /* FIXME: LOCK_MASK? */
1116 scp->status &= ~LED_MASK;
1117 scp->status |= *(int *)data;
1118 if (scp == sc->cur_scp)
1119 update_kbd_leds(scp, scp->status);
1122 case KDGETLED: /* get keyboard LED status */
1123 if (scp == sc->cur_scp)
1124 save_kbd_state(scp);
1125 *(int *)data = scp->status & LED_MASK;
1128 case CONS_SETKBD: /* set the new keyboard */
1133 newkbd = kbd_get_keyboard(*(int *)data);
1134 if (newkbd == NULL) {
1139 if (sc->kbd != newkbd) {
1140 i = kbd_allocate(newkbd->kb_name, newkbd->kb_unit,
1141 (void *)&sc->keyboard, sckbdevent, sc);
1142 /* i == newkbd->kb_index */
1144 if (sc->kbd != NULL) {
1145 save_kbd_state(sc->cur_scp);
1146 kbd_release(sc->kbd, (void *)&sc->keyboard);
1148 sc->kbd = kbd_get_keyboard(i); /* sc->kbd == newkbd */
1150 kbd_ioctl(sc->kbd, KDSKBMODE,
1151 (caddr_t)&sc->cur_scp->kbd_mode);
1152 update_kbd_state(sc->cur_scp, sc->cur_scp->status,
1155 error = EPERM; /* XXX */
1162 case CONS_RELKBD: /* release the current keyboard */
1165 if (sc->kbd != NULL) {
1166 save_kbd_state(sc->cur_scp);
1167 error = kbd_release(sc->kbd, (void *)&sc->keyboard);
1176 case CONS_GETTERM: /* get the current terminal emulator info */
1180 if (((term_info_t *)data)->ti_index == 0) {
1183 sw = sc_term_match_by_number(((term_info_t *)data)->ti_index);
1186 strncpy(((term_info_t *)data)->ti_name, sw->te_name,
1187 sizeof(((term_info_t *)data)->ti_name));
1188 strncpy(((term_info_t *)data)->ti_desc, sw->te_desc,
1189 sizeof(((term_info_t *)data)->ti_desc));
1190 ((term_info_t *)data)->ti_flags = 0;
1193 ((term_info_t *)data)->ti_name[0] = '\0';
1194 ((term_info_t *)data)->ti_desc[0] = '\0';
1195 ((term_info_t *)data)->ti_flags = 0;
1200 case CONS_SETTERM: /* set the current terminal emulator */
1202 error = sc_init_emulator(scp, ((term_info_t *)data)->ti_name);
1203 /* FIXME: what if scp == sc_console! XXX */
1207 case GIO_SCRNMAP: /* get output translation table */
1208 bcopy(&sc->scr_map, data, sizeof(sc->scr_map));
1211 case PIO_SCRNMAP: /* set output translation table */
1212 bcopy(data, &sc->scr_map, sizeof(sc->scr_map));
1213 for (i=0; i<sizeof(sc->scr_map); i++) {
1214 sc->scr_rmap[sc->scr_map[i]] = i;
1218 case GIO_KEYMAP: /* get keyboard translation table */
1219 case PIO_KEYMAP: /* set keyboard translation table */
1220 case GIO_DEADKEYMAP: /* get accent key translation table */
1221 case PIO_DEADKEYMAP: /* set accent key translation table */
1222 case GETFKEY: /* get function key string */
1223 case SETFKEY: /* set function key string */
1224 error = kbd_ioctl(sc->kbd, cmd, data);
1225 if (error == ENOIOCTL)
1229 #ifndef SC_NO_FONT_LOADING
1231 case PIO_FONT8x8: /* set 8x8 dot font */
1232 if (!ISFONTAVAIL(sc->adp->va_flags))
1234 bcopy(data, sc->font_8, 8*256);
1235 sc->fonts_loaded |= FONT_8;
1238 * Always use the font page #0. XXX
1239 * Don't load if the current font size is not 8x8.
1241 if (ISTEXTSC(sc->cur_scp) && (sc->cur_scp->font_size < 14))
1242 sc_load_font(sc->cur_scp, 0, 8, sc->font_8, 0, 256);
1245 case GIO_FONT8x8: /* get 8x8 dot font */
1246 if (!ISFONTAVAIL(sc->adp->va_flags))
1248 if (sc->fonts_loaded & FONT_8) {
1249 bcopy(sc->font_8, data, 8*256);
1255 case PIO_FONT8x14: /* set 8x14 dot font */
1256 if (!ISFONTAVAIL(sc->adp->va_flags))
1258 bcopy(data, sc->font_14, 14*256);
1259 sc->fonts_loaded |= FONT_14;
1262 * Always use the font page #0. XXX
1263 * Don't load if the current font size is not 8x14.
1265 if (ISTEXTSC(sc->cur_scp)
1266 && (sc->cur_scp->font_size >= 14)
1267 && (sc->cur_scp->font_size < 16))
1268 sc_load_font(sc->cur_scp, 0, 14, sc->font_14, 0, 256);
1271 case GIO_FONT8x14: /* get 8x14 dot font */
1272 if (!ISFONTAVAIL(sc->adp->va_flags))
1274 if (sc->fonts_loaded & FONT_14) {
1275 bcopy(sc->font_14, data, 14*256);
1281 case PIO_FONT8x16: /* set 8x16 dot font */
1282 if (!ISFONTAVAIL(sc->adp->va_flags))
1284 bcopy(data, sc->font_16, 16*256);
1285 sc->fonts_loaded |= FONT_16;
1288 * Always use the font page #0. XXX
1289 * Don't load if the current font size is not 8x16.
1291 if (ISTEXTSC(sc->cur_scp) && (sc->cur_scp->font_size >= 16))
1292 sc_load_font(sc->cur_scp, 0, 16, sc->font_16, 0, 256);
1295 case GIO_FONT8x16: /* get 8x16 dot font */
1296 if (!ISFONTAVAIL(sc->adp->va_flags))
1298 if (sc->fonts_loaded & FONT_16) {
1299 bcopy(sc->font_16, data, 16*256);
1305 #endif /* SC_NO_FONT_LOADING */
1311 error = (*linesw[tp->t_line].l_ioctl)(tp, cmd, data, flag, ap->a_cred);
1312 if (error != ENOIOCTL)
1314 error = ttioctl(tp, cmd, data, flag);
1315 if (error != ENOIOCTL)
1321 scstart(struct tty *tp)
1325 u_char buf[PCBURST];
1326 scr_stat *scp = SC_STAT(tp->t_dev);
1328 if (scp->status & SLKED ||
1329 (scp == scp->sc->cur_scp && scp->sc->blink_in_progress))
1332 if (!(tp->t_state & (TS_TIMEOUT | TS_BUSY | TS_TTSTOP))) {
1333 tp->t_state |= TS_BUSY;
1336 len = q_to_b(rbp, buf, PCBURST);
1338 sc_puts(scp, buf, len);
1341 tp->t_state &= ~TS_BUSY;
1348 sccnprobe(struct consdev *cp)
1353 cp->cn_pri = sc_get_cons_priority(&unit, &flags);
1355 /* a video card is always required */
1356 if (!scvidprobe(unit, flags, TRUE))
1357 cp->cn_pri = CN_DEAD;
1359 /* syscons will become console even when there is no keyboard */
1360 sckbdprobe(unit, flags, TRUE);
1362 if (cp->cn_pri == CN_DEAD)
1365 /* initialize required fields */
1366 cp->cn_probegood = 1;
1370 sccninit(struct consdev *cp)
1375 sc_get_cons_priority(&unit, &flags);
1376 scinit(unit, flags | SC_KERNEL_CONSOLE);
1377 sc_console_unit = unit;
1378 sc_console = sc_get_softc(unit, SC_KERNEL_CONSOLE)->console_scp;
1382 sccninit_fini(struct consdev *cp)
1384 if (cctl_dev == NULL)
1385 kprintf("sccninit_fini: WARNING: cctl_dev is NULL!\n");
1386 cp->cn_dev = cctl_dev;
1390 sccnterm(struct consdev *cp)
1392 /* we are not the kernel console any more, release everything */
1394 if (sc_console_unit < 0)
1395 return; /* shouldn't happen */
1398 sc_clear_screen(sc_console);
1399 sccnupdate(sc_console);
1401 scterm(sc_console_unit, SC_KERNEL_CONSOLE);
1402 sc_console_unit = -1;
1407 sccnputc(void *private, int c)
1410 scr_stat *scp = sc_console;
1412 #ifndef SC_NO_HISTORY
1414 #endif /* !SC_NO_HISTORY */
1416 /* assert(sc_console != NULL) */
1418 #ifndef SC_NO_HISTORY
1419 if (scp == scp->sc->cur_scp && scp->status & SLKED) {
1420 scp->status &= ~SLKED;
1421 update_kbd_state(scp, scp->status, SLKED);
1422 if (scp->status & BUFFER_SAVED) {
1423 if (!sc_hist_restore(scp))
1424 sc_remove_cutmarking(scp);
1425 scp->status &= ~BUFFER_SAVED;
1426 scp->status |= CURSOR_ENABLED;
1427 sc_draw_cursor_image(scp);
1429 tp = VIRTUAL_TTY(scp->sc, scp->index);
1433 #endif /* !SC_NO_HISTORY */
1436 if (kernel_console_ts != NULL)
1437 scp->ts = kernel_console_ts;
1439 sc_puts(scp, buf, 1);
1448 sccngetc(void *private)
1450 return sccngetch(0);
1454 sccncheckc(void *private)
1456 return sccngetch(SCGETC_NONBLOCK);
1460 sccndbctl(void *private, int on)
1462 /* assert(sc_console_unit >= 0) */
1463 /* try to switch to the kernel console screen */
1464 if (on && debugger == 0) {
1466 * TRY to make sure the screen saver is stopped,
1467 * and the screen is updated before switching to
1472 && sc_console->sc->cur_scp->smode.mode == VT_AUTO
1473 && sc_console->smode.mode == VT_AUTO) {
1474 sc_console->sc->cur_scp->status |= MOUSE_HIDDEN;
1475 sc_switch_scr(sc_console->sc, sc_console->index);
1485 sccngetch(int flags)
1487 static struct fkeytab fkey;
1495 /* assert(sc_console != NULL) */
1498 * Stop the screen saver and update the screen if necessary.
1499 * What if we have been running in the screen saver code... XXX
1501 sc_touch_scrn_saver();
1502 scp = sc_console->sc->cur_scp; /* XXX */
1505 if (fkeycp < fkey.len) {
1507 return fkey.str[fkeycp++];
1510 if (scp->sc->kbd == NULL) {
1516 * Make sure the keyboard is accessible even when the kbd device
1517 * driver is disabled.
1519 kbd_enable(scp->sc->kbd);
1521 /* we shall always use the keyboard in the XLATE mode here */
1522 cur_mode = scp->kbd_mode;
1523 scp->kbd_mode = K_XLATE;
1524 kbd_ioctl(scp->sc->kbd, KDSKBMODE, (caddr_t)&scp->kbd_mode);
1526 kbd_poll(scp->sc->kbd, TRUE);
1527 c = scgetc(scp->sc, SCGETC_CN | flags);
1528 kbd_poll(scp->sc->kbd, FALSE);
1530 scp->kbd_mode = cur_mode;
1531 kbd_ioctl(scp->sc->kbd, KDSKBMODE, (caddr_t)&scp->kbd_mode);
1532 kbd_disable(scp->sc->kbd);
1535 switch (KEYFLAGS(c)) {
1536 case 0: /* normal char */
1538 case FKEY: /* function key */
1539 p = kbd_get_fkeystr(scp->sc->kbd, KEYCHAR(c), (size_t *)&fkeycp);
1541 if ((p != NULL) && (fkey.len > 0)) {
1542 bcopy(p, fkey.str, fkey.len);
1556 sccnupdate(scr_stat *scp)
1558 /* this is a cut-down version of scrn_timer()... */
1560 if (scp->sc->font_loading_in_progress || scp->sc->videoio_in_progress)
1563 if (debugger > 0 || panicstr || shutdown_in_progress) {
1564 sc_touch_scrn_saver();
1565 } else if (scp != scp->sc->cur_scp) {
1569 if (!run_scrn_saver)
1570 scp->sc->flags &= ~SC_SCRN_IDLE;
1572 if ((saver_mode != CONS_LKM_SAVER) || !(scp->sc->flags & SC_SCRN_IDLE))
1573 if (scp->sc->flags & SC_SCRN_BLANKED)
1574 stop_scrn_saver(scp->sc, current_saver);
1575 #endif /* NSPLASH */
1577 if (scp != scp->sc->cur_scp || scp->sc->blink_in_progress
1578 || scp->sc->switch_in_progress)
1581 * FIXME: unlike scrn_timer(), we call scrn_update() from here even
1582 * when write_in_progress is non-zero. XXX
1585 if (!ISGRAPHSC(scp) && !(scp->sc->flags & SC_SCRN_BLANKED))
1586 scrn_update(scp, TRUE);
1590 scrn_timer(void *arg)
1592 static int kbd_interval = 0;
1598 again = (arg != NULL);
1600 sc = (sc_softc_t *)arg;
1601 else if (sc_console != NULL)
1602 sc = sc_console->sc;
1606 /* don't do anything when we are performing some I/O operations */
1607 if (sc->font_loading_in_progress || sc->videoio_in_progress) {
1609 callout_reset(&sc->scrn_timer_ch, hz / 10, scrn_timer, sc);
1614 if ((sc->kbd == NULL) && (sc->config & SC_AUTODETECT_KBD)) {
1615 /* try to allocate a keyboard automatically */
1616 if (++kbd_interval >= 25) {
1617 sc->keyboard = kbd_allocate("*", -1, (void *)&sc->keyboard,
1619 if (sc->keyboard >= 0) {
1620 sc->kbd = kbd_get_keyboard(sc->keyboard);
1621 kbd_ioctl(sc->kbd, KDSKBMODE,
1622 (caddr_t)&sc->cur_scp->kbd_mode);
1623 update_kbd_state(sc->cur_scp, sc->cur_scp->status,
1630 /* should we stop the screen saver? */
1631 getmicrouptime(&tv);
1632 if (debugger > 0 || panicstr || shutdown_in_progress)
1633 sc_touch_scrn_saver();
1634 if (run_scrn_saver) {
1635 if (tv.tv_sec > sc->scrn_time_stamp + scrn_blank_time)
1636 sc->flags |= SC_SCRN_IDLE;
1638 sc->flags &= ~SC_SCRN_IDLE;
1640 sc->scrn_time_stamp = tv.tv_sec;
1641 sc->flags &= ~SC_SCRN_IDLE;
1642 if (scrn_blank_time > 0)
1643 run_scrn_saver = TRUE;
1646 if ((saver_mode != CONS_LKM_SAVER) || !(sc->flags & SC_SCRN_IDLE))
1647 if (sc->flags & SC_SCRN_BLANKED)
1648 stop_scrn_saver(sc, current_saver);
1649 #endif /* NSPLASH */
1651 /* should we just return ? */
1652 if (sc->blink_in_progress || sc->switch_in_progress
1653 || sc->write_in_progress) {
1655 callout_reset(&sc->scrn_timer_ch, hz / 10, scrn_timer, sc);
1660 /* Update the screen */
1661 scp = sc->cur_scp; /* cur_scp may have changed... */
1662 if (!ISGRAPHSC(scp) && !(sc->flags & SC_SCRN_BLANKED))
1663 scrn_update(scp, TRUE);
1666 /* should we activate the screen saver? */
1667 if ((saver_mode == CONS_LKM_SAVER) && (sc->flags & SC_SCRN_IDLE))
1668 if (!ISGRAPHSC(scp) || (sc->flags & SC_SCRN_BLANKED))
1669 (*current_saver)(sc, TRUE);
1670 #endif /* NSPLASH */
1673 callout_reset(&sc->scrn_timer_ch, hz / 25, scrn_timer, sc);
1678 and_region(int *s1, int *e1, int s2, int e2)
1680 if (*e1 < s2 || e2 < *s1)
1682 *s1 = imax(*s1, s2);
1683 *e1 = imin(*e1, e2);
1688 scrn_update(scr_stat *scp, int show_cursor)
1695 /* assert(scp == scp->sc->cur_scp) */
1697 ++scp->sc->videoio_in_progress;
1699 #ifndef SC_NO_CUTPASTE
1700 /* remove the previous mouse pointer image if necessary */
1701 if (scp->status & MOUSE_VISIBLE) {
1703 e = scp->mouse_pos + scp->xsize + 1;
1704 if ((scp->status & (MOUSE_MOVED | MOUSE_HIDDEN))
1705 || and_region(&s, &e, scp->start, scp->end)
1706 || ((scp->status & CURSOR_ENABLED) &&
1707 (scp->cursor_pos != scp->cursor_oldpos) &&
1708 (and_region(&s, &e, scp->cursor_pos, scp->cursor_pos)
1709 || and_region(&s, &e, scp->cursor_oldpos, scp->cursor_oldpos)))) {
1710 sc_remove_mouse_image(scp);
1711 if (scp->end >= scp->xsize*scp->ysize)
1712 scp->end = scp->xsize*scp->ysize - 1;
1715 #endif /* !SC_NO_CUTPASTE */
1719 if (scp->end >= scp->xsize*scp->ysize) {
1720 kprintf("scrn_update(): scp->end %d > size_of_screen!!\n", scp->end);
1721 scp->end = scp->xsize*scp->ysize - 1;
1723 if (scp->start < 0) {
1724 kprintf("scrn_update(): scp->start %d < 0\n", scp->start);
1729 /* update screen image */
1730 if (scp->start <= scp->end) {
1731 if (scp->mouse_cut_end >= 0) {
1732 /* there is a marked region for cut & paste */
1733 if (scp->mouse_cut_start <= scp->mouse_cut_end) {
1734 start = scp->mouse_cut_start;
1735 end = scp->mouse_cut_end;
1737 start = scp->mouse_cut_end;
1738 end = scp->mouse_cut_start - 1;
1742 /* does the cut-mark region overlap with the update region? */
1743 if (and_region(&s, &e, scp->start, scp->end)) {
1744 (*scp->rndr->draw)(scp, s, e - s + 1, TRUE);
1747 if (and_region(&s, &e, scp->start, scp->end))
1748 (*scp->rndr->draw)(scp, s, e - s + 1, FALSE);
1750 e = scp->xsize*scp->ysize - 1;
1751 if (and_region(&s, &e, scp->start, scp->end))
1752 (*scp->rndr->draw)(scp, s, e - s + 1, FALSE);
1754 (*scp->rndr->draw)(scp, scp->start,
1755 scp->end - scp->start + 1, FALSE);
1758 (*scp->rndr->draw)(scp, scp->start,
1759 scp->end - scp->start + 1, FALSE);
1763 /* we are not to show the cursor and the mouse pointer... */
1766 scp->start = scp->xsize*scp->ysize - 1;
1767 --scp->sc->videoio_in_progress;
1771 /* update cursor image */
1772 if (scp->status & CURSOR_ENABLED) {
1775 /* did cursor move since last time ? */
1776 if (scp->cursor_pos != scp->cursor_oldpos) {
1777 /* do we need to remove old cursor image ? */
1778 if (!and_region(&s, &e, scp->cursor_oldpos, scp->cursor_oldpos))
1779 sc_remove_cursor_image(scp);
1780 sc_draw_cursor_image(scp);
1782 if (and_region(&s, &e, scp->cursor_pos, scp->cursor_pos))
1783 /* cursor didn't move, but has been overwritten */
1784 sc_draw_cursor_image(scp);
1785 else if (scp->sc->flags & SC_BLINK_CURSOR)
1786 /* if it's a blinking cursor, update it */
1787 (*scp->rndr->blink_cursor)(scp, scp->cursor_pos,
1788 sc_inside_cutmark(scp,
1793 #ifndef SC_NO_CUTPASTE
1794 /* update "pseudo" mouse pointer image */
1795 if (scp->sc->flags & SC_MOUSE_ENABLED) {
1796 if (!(scp->status & (MOUSE_VISIBLE | MOUSE_HIDDEN))) {
1797 scp->status &= ~MOUSE_MOVED;
1798 sc_draw_mouse_image(scp);
1801 #endif /* SC_NO_CUTPASTE */
1804 scp->start = scp->xsize*scp->ysize - 1;
1806 --scp->sc->videoio_in_progress;
1811 scsplash_callback(int event, void *arg)
1816 sc = (sc_softc_t *)arg;
1820 if (add_scrn_saver(scsplash_saver) == 0) {
1821 sc->flags &= ~SC_SAVER_FAILED;
1822 run_scrn_saver = TRUE;
1823 if (cold && !(boothowto & (RB_VERBOSE | RB_CONFIG))) {
1824 scsplash_stick(TRUE);
1825 (*current_saver)(sc, TRUE);
1831 if (current_saver == scsplash_saver) {
1832 scsplash_stick(FALSE);
1833 error = remove_scrn_saver(scsplash_saver);
1845 scsplash_saver(sc_softc_t *sc, int show)
1847 static int busy = FALSE;
1856 if (!(sc->flags & SC_SAVER_FAILED)) {
1857 if (!(sc->flags & SC_SCRN_BLANKED))
1858 set_scrn_saver_mode(scp, -1, NULL, 0);
1859 switch (splash(sc->adp, TRUE)) {
1860 case 0: /* succeeded */
1862 case EAGAIN: /* try later */
1863 restore_scrn_saver_mode(scp, FALSE);
1864 sc_touch_scrn_saver(); /* XXX */
1867 sc->flags |= SC_SAVER_FAILED;
1868 scsplash_stick(FALSE);
1869 restore_scrn_saver_mode(scp, TRUE);
1870 kprintf("scsplash_saver(): failed to put up the image\n");
1874 } else if (!sticky_splash) {
1875 if ((sc->flags & SC_SCRN_BLANKED) && (splash(sc->adp, FALSE) == 0))
1876 restore_scrn_saver_mode(scp, TRUE);
1882 add_scrn_saver(void (*this_saver)(sc_softc_t *, int))
1887 if (current_saver != none_saver) {
1888 error = remove_scrn_saver(current_saver);
1893 if (current_saver != none_saver)
1896 run_scrn_saver = FALSE;
1897 saver_mode = CONS_LKM_SAVER;
1898 current_saver = this_saver;
1903 remove_scrn_saver(void (*this_saver)(sc_softc_t *, int))
1905 if (current_saver != this_saver)
1910 * In order to prevent `current_saver' from being called by
1911 * the timeout routine `scrn_timer()' while we manipulate
1912 * the saver list, we shall set `current_saver' to `none_saver'
1913 * before stopping the current saver, rather than blocking by `splXX()'.
1915 current_saver = none_saver;
1917 stop_scrn_saver(this_saver);
1920 /* unblank all blanked screens */
1921 wait_scrn_saver_stop(NULL);
1925 current_saver = none_saver;
1930 set_scrn_saver_mode(scr_stat *scp, int mode, u_char *pal, int border)
1933 /* assert(scp == scp->sc->cur_scp) */
1935 if (!ISGRAPHSC(scp))
1936 sc_remove_cursor_image(scp);
1937 scp->splash_save_mode = scp->mode;
1938 scp->splash_save_status = scp->status & (GRAPHICS_MODE | PIXEL_MODE);
1939 scp->status &= ~(GRAPHICS_MODE | PIXEL_MODE);
1940 scp->status |= (UNKNOWN_MODE | SAVER_RUNNING);
1941 scp->sc->flags |= SC_SCRN_BLANKED;
1947 if (set_mode(scp) == 0) {
1948 if (scp->sc->adp->va_info.vi_flags & V_INFO_GRAPHICS)
1949 scp->status |= GRAPHICS_MODE;
1950 #ifndef SC_NO_PALETTE_LOADING
1952 load_palette(scp->sc->adp, pal);
1954 sc_set_border(scp, border);
1958 scp->mode = scp->splash_save_mode;
1959 scp->status &= ~(UNKNOWN_MODE | SAVER_RUNNING);
1960 scp->status |= scp->splash_save_status;
1967 restore_scrn_saver_mode(scr_stat *scp, int changemode)
1972 /* assert(scp == scp->sc->cur_scp) */
1975 status = scp->status;
1976 scp->mode = scp->splash_save_mode;
1977 scp->status &= ~(UNKNOWN_MODE | SAVER_RUNNING);
1978 scp->status |= scp->splash_save_status;
1979 scp->sc->flags &= ~SC_SCRN_BLANKED;
1981 if (!ISGRAPHSC(scp))
1982 sc_draw_cursor_image(scp);
1987 if (set_mode(scp) == 0) {
1988 #ifndef SC_NO_PALETTE_LOADING
1989 load_palette(scp->sc->adp, scp->sc->palette);
1996 scp->status = status;
2003 stop_scrn_saver(sc_softc_t *sc, void (*saver)(sc_softc_t *, int))
2005 (*saver)(sc, FALSE);
2006 run_scrn_saver = FALSE;
2007 /* the screen saver may have chosen not to stop after all... */
2008 if (sc->flags & SC_SCRN_BLANKED)
2011 mark_all(sc->cur_scp);
2012 if (sc->delayed_next_scr)
2013 sc_switch_scr(sc, sc->delayed_next_scr - 1);
2014 wakeup((caddr_t)&scrn_blanked);
2018 wait_scrn_saver_stop(sc_softc_t *sc)
2022 while (scrn_blanked > 0) {
2023 run_scrn_saver = FALSE;
2024 if (sc && !(sc->flags & SC_SCRN_BLANKED)) {
2028 error = tsleep((caddr_t)&scrn_blanked, PCATCH, "scrsav", 0);
2029 /* May return ERESTART */
2033 run_scrn_saver = FALSE;
2036 #endif /* NSPLASH */
2039 sc_touch_scrn_saver(void)
2041 scsplash_stick(FALSE);
2042 run_scrn_saver = FALSE;
2046 sc_switch_scr(sc_softc_t *sc, u_int next_scr)
2051 DPRINTF(5, ("sc0: sc_switch_scr() %d ", next_scr + 1));
2053 /* prevent switch if previously requested */
2054 if (sc->flags & SC_SCRN_VTYLOCK) {
2055 sc_bell(sc->cur_scp, sc->cur_scp->bell_pitch,
2056 sc->cur_scp->bell_duration);
2060 /* delay switch if the screen is blanked or being updated */
2061 if ((sc->flags & SC_SCRN_BLANKED) || sc->write_in_progress
2062 || sc->blink_in_progress || sc->videoio_in_progress) {
2063 sc->delayed_next_scr = next_scr + 1;
2064 sc_touch_scrn_saver();
2065 DPRINTF(5, ("switch delayed\n"));
2070 cur_scp = sc->cur_scp;
2072 /* we are in the middle of the vty switching process... */
2073 if (sc->switch_in_progress
2074 && (cur_scp->smode.mode == VT_PROCESS)
2076 if (cur_scp->proc != pfind(cur_scp->pid)) {
2078 * The controlling process has died!!. Do some clean up.
2079 * NOTE:`cur_scp->proc' and `cur_scp->smode.mode'
2080 * are not reset here yet; they will be cleared later.
2082 DPRINTF(5, ("cur_scp controlling process %d died, ",
2084 if (cur_scp->status & SWITCH_WAIT_REL) {
2086 * Force the previous switch to finish, but return now
2089 * note: must be called from a critical section because
2090 * finish_vt_rel will call do_switch_scr which releases it
2093 DPRINTF(5, ("reset WAIT_REL, "));
2094 finish_vt_rel(cur_scp, TRUE);
2096 DPRINTF(5, ("finishing previous switch\n"));
2098 } else if (cur_scp->status & SWITCH_WAIT_ACQ) {
2099 /* let's assume screen switch has been completed. */
2100 DPRINTF(5, ("reset WAIT_ACQ, "));
2101 finish_vt_acq(cur_scp);
2104 * We are in between screen release and acquisition, and
2105 * reached here via scgetc() or scrn_timer() which has
2106 * interrupted exchange_scr(). Don't do anything stupid.
2108 DPRINTF(5, ("waiting nothing, "));
2112 * The controlling process is alive, but not responding...
2113 * It is either buggy or it may be just taking time.
2114 * The following code is a gross kludge to cope with this
2115 * problem for which there is no clean solution. XXX
2117 if (cur_scp->status & SWITCH_WAIT_REL) {
2118 switch (sc->switch_in_progress++) {
2122 DPRINTF(5, ("sending relsig again, "));
2123 signal_vt_rel(cur_scp);
2130 * Act as if the controlling program returned
2133 * note: must be called from a critical section because
2134 * finish_vt_rel will call do_switch_scr which releases it
2137 DPRINTF(5, ("force reset WAIT_REL, "));
2138 finish_vt_rel(cur_scp, FALSE);
2140 DPRINTF(5, ("act as if VT_FALSE was seen\n"));
2143 } else if (cur_scp->status & SWITCH_WAIT_ACQ) {
2144 switch (sc->switch_in_progress++) {
2148 DPRINTF(5, ("sending acqsig again, "));
2149 signal_vt_acq(cur_scp);
2155 /* clear the flag and finish the previous switch */
2156 DPRINTF(5, ("force reset WAIT_ACQ, "));
2157 finish_vt_acq(cur_scp);
2165 * Return error if an invalid argument is given, or vty switch
2166 * is still in progress.
2168 if ((next_scr < sc->first_vty) || (next_scr >= sc->first_vty + sc->vtys)
2169 || sc->switch_in_progress) {
2171 sc_bell(cur_scp, bios_value.bell_pitch, BELL_DURATION);
2172 DPRINTF(5, ("error 1\n"));
2177 * Don't allow switching away from the graphics mode vty
2178 * if the switch mode is VT_AUTO, unless the next vty is the same
2179 * as the current or the current vty has been closed (but showing).
2181 tp = VIRTUAL_TTY(sc, cur_scp->index);
2182 if ((cur_scp->index != next_scr)
2184 && (cur_scp->smode.mode == VT_AUTO)
2185 && ISGRAPHSC(cur_scp)) {
2187 sc_bell(cur_scp, bios_value.bell_pitch, BELL_DURATION);
2188 DPRINTF(5, ("error, graphics mode\n"));
2193 * Is the wanted vty open? Don't allow switching to a closed vty.
2194 * If we are in DDB, don't switch to a vty in the VT_PROCESS mode.
2195 * Note that we always allow the user to switch to the kernel
2196 * console even if it is closed.
2198 if ((sc_console == NULL) || (next_scr != sc_console->index)) {
2199 tp = VIRTUAL_TTY(sc, next_scr);
2200 if (!ISTTYOPEN(tp)) {
2202 sc_bell(cur_scp, bios_value.bell_pitch, BELL_DURATION);
2203 DPRINTF(5, ("error 2, requested vty isn't open!\n"));
2206 if ((debugger > 0) && (SC_STAT(tp->t_dev)->smode.mode == VT_PROCESS)) {
2208 DPRINTF(5, ("error 3, requested vty is in the VT_PROCESS mode\n"));
2213 /* this is the start of vty switching process... */
2214 ++sc->switch_in_progress;
2215 sc->delayed_next_scr = 0;
2216 sc->old_scp = cur_scp;
2217 sc->new_scp = SC_STAT(SC_DEV(sc, next_scr));
2218 if (sc->new_scp == sc->old_scp) {
2219 sc->switch_in_progress = 0;
2220 wakeup((caddr_t)&sc->new_scp->smode);
2222 DPRINTF(5, ("switch done (new == old)\n"));
2226 /* has controlling process died? */
2227 vt_proc_alive(sc->old_scp);
2228 vt_proc_alive(sc->new_scp);
2230 /* wait for the controlling process to release the screen, if necessary */
2231 if (signal_vt_rel(sc->old_scp)) {
2236 /* go set up the new vty screen */
2241 /* wake up processes waiting for this vty */
2242 wakeup((caddr_t)&sc->cur_scp->smode);
2244 /* wait for the controlling process to acknowledge, if necessary */
2245 if (signal_vt_acq(sc->cur_scp)) {
2250 sc->switch_in_progress = 0;
2251 if (sc->unit == sc_console_unit)
2252 cons_unavail = FALSE;
2254 DPRINTF(5, ("switch done\n"));
2260 * NOTE: must be called from a critical section because do_switch_scr
2261 * will release it temporarily.
2264 do_switch_scr(sc_softc_t *sc)
2266 vt_proc_alive(sc->new_scp);
2271 /* sc->cur_scp == sc->new_scp */
2272 wakeup((caddr_t)&sc->cur_scp->smode);
2274 /* wait for the controlling process to acknowledge, if necessary */
2275 if (!signal_vt_acq(sc->cur_scp)) {
2276 sc->switch_in_progress = 0;
2277 if (sc->unit == sc_console_unit)
2278 cons_unavail = FALSE;
2283 vt_proc_alive(scr_stat *scp)
2286 if (scp->proc == pfind(scp->pid))
2289 scp->smode.mode = VT_AUTO;
2290 DPRINTF(5, ("vt controlling process %d died\n", scp->pid));
2296 signal_vt_rel(scr_stat *scp)
2298 if (scp->smode.mode != VT_PROCESS)
2300 scp->status |= SWITCH_WAIT_REL;
2301 ksignal(scp->proc, scp->smode.relsig);
2302 DPRINTF(5, ("sending relsig to %d\n", scp->pid));
2307 signal_vt_acq(scr_stat *scp)
2309 if (scp->smode.mode != VT_PROCESS)
2311 if (scp->sc->unit == sc_console_unit)
2312 cons_unavail = TRUE;
2313 scp->status |= SWITCH_WAIT_ACQ;
2314 ksignal(scp->proc, scp->smode.acqsig);
2315 DPRINTF(5, ("sending acqsig to %d\n", scp->pid));
2320 * NOTE: must be called from a critical section because do_switch_scr
2321 * will release it temporarily.
2324 finish_vt_rel(scr_stat *scp, int release)
2326 if (scp == scp->sc->old_scp && scp->status & SWITCH_WAIT_REL) {
2327 scp->status &= ~SWITCH_WAIT_REL;
2329 do_switch_scr(scp->sc);
2331 scp->sc->switch_in_progress = 0;
2338 finish_vt_acq(scr_stat *scp)
2340 if (scp == scp->sc->new_scp && scp->status & SWITCH_WAIT_ACQ) {
2341 scp->status &= ~SWITCH_WAIT_ACQ;
2342 scp->sc->switch_in_progress = 0;
2349 exchange_scr(sc_softc_t *sc)
2353 /* save the current state of video and keyboard */
2354 sc_move_cursor(sc->old_scp, sc->old_scp->xpos, sc->old_scp->ypos);
2355 if (!ISGRAPHSC(sc->old_scp))
2356 sc_remove_cursor_image(sc->old_scp);
2357 if (sc->old_scp->kbd_mode == K_XLATE)
2358 save_kbd_state(sc->old_scp);
2360 /* set up the video for the new screen */
2361 scp = sc->cur_scp = sc->new_scp;
2362 if (sc->old_scp->mode != scp->mode || ISUNKNOWNSC(sc->old_scp))
2365 sc_vtb_init(&scp->scr, VTB_FRAMEBUFFER, scp->xsize, scp->ysize,
2366 (void *)sc->adp->va_window, FALSE);
2367 scp->status |= MOUSE_HIDDEN;
2368 sc_move_cursor(scp, scp->xpos, scp->ypos);
2369 if (!ISGRAPHSC(scp))
2370 sc_set_cursor_image(scp);
2371 #ifndef SC_NO_PALETTE_LOADING
2372 if (ISGRAPHSC(sc->old_scp))
2373 load_palette(sc->adp, sc->palette);
2375 sc_set_border(scp, scp->border);
2377 /* set up the keyboard for the new screen */
2378 if (sc->old_scp->kbd_mode != scp->kbd_mode)
2379 kbd_ioctl(sc->kbd, KDSKBMODE, (caddr_t)&scp->kbd_mode);
2380 update_kbd_state(scp, scp->status, LOCK_MASK);
2386 sc_puts(scr_stat *scp, u_char *buf, int len)
2389 /* make screensaver happy */
2390 if (!sticky_splash && scp == scp->sc->cur_scp)
2391 run_scrn_saver = FALSE;
2395 (*scp->tsw->te_puts)(scp, buf, len);
2397 if (scp->sc->delayed_next_scr)
2398 sc_switch_scr(scp->sc, scp->sc->delayed_next_scr - 1);
2402 sc_draw_cursor_image(scr_stat *scp)
2404 /* assert(scp == scp->sc->cur_scp); */
2405 ++scp->sc->videoio_in_progress;
2406 (*scp->rndr->draw_cursor)(scp, scp->cursor_pos,
2407 scp->sc->flags & SC_BLINK_CURSOR, TRUE,
2408 sc_inside_cutmark(scp, scp->cursor_pos));
2409 scp->cursor_oldpos = scp->cursor_pos;
2410 --scp->sc->videoio_in_progress;
2414 sc_remove_cursor_image(scr_stat *scp)
2416 /* assert(scp == scp->sc->cur_scp); */
2417 ++scp->sc->videoio_in_progress;
2418 (*scp->rndr->draw_cursor)(scp, scp->cursor_oldpos,
2419 scp->sc->flags & SC_BLINK_CURSOR, FALSE,
2420 sc_inside_cutmark(scp, scp->cursor_oldpos));
2421 --scp->sc->videoio_in_progress;
2425 update_cursor_image(scr_stat *scp)
2429 if (scp->sc->flags & SC_CHAR_CURSOR) {
2430 scp->cursor_base = imax(0, scp->sc->cursor_base);
2431 scp->cursor_height = imin(scp->sc->cursor_height, scp->font_size);
2433 scp->cursor_base = 0;
2434 scp->cursor_height = scp->font_size;
2436 blink = scp->sc->flags & SC_BLINK_CURSOR;
2438 /* assert(scp == scp->sc->cur_scp); */
2439 ++scp->sc->videoio_in_progress;
2440 (*scp->rndr->draw_cursor)(scp, scp->cursor_oldpos, blink, FALSE,
2441 sc_inside_cutmark(scp, scp->cursor_pos));
2442 (*scp->rndr->set_cursor)(scp, scp->cursor_base, scp->cursor_height, blink);
2443 (*scp->rndr->draw_cursor)(scp, scp->cursor_pos, blink, TRUE,
2444 sc_inside_cutmark(scp, scp->cursor_pos));
2445 --scp->sc->videoio_in_progress;
2449 sc_set_cursor_image(scr_stat *scp)
2451 if (scp->sc->flags & SC_CHAR_CURSOR) {
2452 scp->cursor_base = imax(0, scp->sc->cursor_base);
2453 scp->cursor_height = imin(scp->sc->cursor_height, scp->font_size);
2455 scp->cursor_base = 0;
2456 scp->cursor_height = scp->font_size;
2459 /* assert(scp == scp->sc->cur_scp); */
2460 ++scp->sc->videoio_in_progress;
2461 (*scp->rndr->set_cursor)(scp, scp->cursor_base, scp->cursor_height,
2462 scp->sc->flags & SC_BLINK_CURSOR);
2463 --scp->sc->videoio_in_progress;
2467 scinit(int unit, int flags)
2470 * When syscons is being initialized as the kernel console, malloc()
2471 * is not yet functional, because various kernel structures has not been
2472 * fully initialized yet. Therefore, we need to declare the following
2473 * static buffers for the console. This is less than ideal,
2474 * but is necessry evil for the time being. XXX
2476 static scr_stat main_console;
2477 static u_short sc_buffer[ROW*COL]; /* XXX */
2478 #ifndef SC_NO_FONT_LOADING
2479 static u_char font_8[256*8];
2480 static u_char font_14[256*14];
2481 static u_char font_16[256*16];
2486 video_adapter_t *adp;
2491 /* one time initialization */
2492 if (init_done == COLD)
2493 sc_get_bios_values(&bios_value);
2497 * Allocate resources. Even if we are being called for the second
2498 * time, we must allocate them again, because they might have
2501 sc = sc_get_softc(unit, flags & SC_KERNEL_CONSOLE);
2503 if (sc->adapter >= 0) {
2504 vid_release(sc->adp, (void *)&sc->adapter);
2508 if (sc->keyboard >= 0) {
2509 DPRINTF(5, ("sc%d: releasing kbd%d\n", unit, sc->keyboard));
2510 i = kbd_release(sc->kbd, (void *)&sc->keyboard);
2511 DPRINTF(5, ("sc%d: kbd_release returned %d\n", unit, i));
2512 if (sc->kbd != NULL) {
2513 DPRINTF(5, ("sc%d: kbd != NULL!, index:%d, unit:%d, flags:0x%x\n",
2514 unit, sc->kbd->kb_index, sc->kbd->kb_unit, sc->kbd->kb_flags));
2518 sc->adapter = vid_allocate("*", unit, (void *)&sc->adapter);
2519 sc->adp = vid_get_adapter(sc->adapter);
2520 /* assert((sc->adapter >= 0) && (sc->adp != NULL)) */
2521 sc->keyboard = kbd_allocate("*", unit, (void *)&sc->keyboard,
2523 DPRINTF(1, ("sc%d: keyboard %d\n", unit, sc->keyboard));
2524 sc->kbd = kbd_get_keyboard(sc->keyboard);
2525 if (sc->kbd != NULL) {
2526 DPRINTF(1, ("sc%d: kbd index:%d, unit:%d, flags:0x%x\n",
2527 unit, sc->kbd->kb_index, sc->kbd->kb_unit, sc->kbd->kb_flags));
2530 if (!(sc->flags & SC_INIT_DONE) || (adp != sc->adp)) {
2532 sc->initial_mode = sc->adp->va_initial_mode;
2534 #ifndef SC_NO_FONT_LOADING
2535 if (flags & SC_KERNEL_CONSOLE) {
2536 sc->font_8 = font_8;
2537 sc->font_14 = font_14;
2538 sc->font_16 = font_16;
2539 } else if (sc->font_8 == NULL) {
2540 /* assert(sc_malloc) */
2541 sc->font_8 = kmalloc(sizeof(font_8), M_SYSCONS, M_WAITOK);
2542 sc->font_14 = kmalloc(sizeof(font_14), M_SYSCONS, M_WAITOK);
2543 sc->font_16 = kmalloc(sizeof(font_16), M_SYSCONS, M_WAITOK);
2547 /* extract the hardware cursor location and hide the cursor for now */
2548 (*vidsw[sc->adapter]->read_hw_cursor)(sc->adp, &col, &row);
2549 (*vidsw[sc->adapter]->set_hw_cursor)(sc->adp, -1, -1);
2551 /* set up the first console */
2552 sc->first_vty = unit*MAXCONS;
2553 sc->vtys = MAXCONS; /* XXX: should be configurable */
2554 if (flags & SC_KERNEL_CONSOLE) {
2555 scp = &main_console;
2556 sc->console_scp = scp;
2557 init_scp(sc, sc->first_vty, scp);
2558 sc_vtb_init(&scp->vtb, VTB_MEMORY, scp->xsize, scp->ysize,
2559 (void *)sc_buffer, FALSE);
2560 if (sc_init_emulator(scp, SC_DFLT_TERM))
2561 sc_init_emulator(scp, "*");
2562 (*scp->tsw->te_default_attr)(scp,
2563 kernel_default.std_color,
2564 kernel_default.rev_color);
2566 /* assert(sc_malloc) */
2567 sc->dev = kmalloc(sizeof(cdev_t)*sc->vtys, M_SYSCONS, M_WAITOK | M_ZERO);
2569 sc->dev[0] = make_dev(&sc_ops, unit*MAXCONS, UID_ROOT,
2570 GID_WHEEL, 0600, "ttyv%r", unit*MAXCONS);
2572 sc->dev[0]->si_tty = ttymalloc(sc->dev[0]->si_tty);
2573 scp = alloc_scp(sc, sc->first_vty);
2574 sc->dev[0]->si_drv1 = scp;
2578 /* copy screen to temporary buffer */
2579 sc_vtb_init(&scp->scr, VTB_FRAMEBUFFER, scp->xsize, scp->ysize,
2580 (void *)scp->sc->adp->va_window, FALSE);
2582 sc_vtb_copy(&scp->scr, 0, &scp->vtb, 0, scp->xsize*scp->ysize);
2584 /* move cursors to the initial positions */
2585 if (col >= scp->xsize)
2587 if (row >= scp->ysize)
2588 row = scp->ysize - 1;
2591 scp->cursor_pos = scp->cursor_oldpos = row*scp->xsize + col;
2592 if (bios_value.cursor_end < scp->font_size)
2593 sc->cursor_base = scp->font_size - bios_value.cursor_end - 1;
2595 sc->cursor_base = 0;
2596 i = bios_value.cursor_end - bios_value.cursor_start + 1;
2597 sc->cursor_height = imin(i, scp->font_size);
2598 #ifndef SC_NO_SYSMOUSE
2599 sc_mouse_move(scp, scp->xpixel/2, scp->ypixel/2);
2601 if (!ISGRAPHSC(scp)) {
2602 sc_set_cursor_image(scp);
2603 sc_draw_cursor_image(scp);
2606 /* save font and palette */
2607 #ifndef SC_NO_FONT_LOADING
2608 sc->fonts_loaded = 0;
2609 if (ISFONTAVAIL(sc->adp->va_flags)) {
2611 bcopy(dflt_font_8, sc->font_8, sizeof(dflt_font_8));
2612 bcopy(dflt_font_14, sc->font_14, sizeof(dflt_font_14));
2613 bcopy(dflt_font_16, sc->font_16, sizeof(dflt_font_16));
2614 sc->fonts_loaded = FONT_16 | FONT_14 | FONT_8;
2615 if (scp->font_size < 14) {
2616 sc_load_font(scp, 0, 8, sc->font_8, 0, 256);
2617 } else if (scp->font_size >= 16) {
2618 sc_load_font(scp, 0, 16, sc->font_16, 0, 256);
2620 sc_load_font(scp, 0, 14, sc->font_14, 0, 256);
2622 #else /* !SC_DFLT_FONT */
2623 if (scp->font_size < 14) {
2624 sc_save_font(scp, 0, 8, sc->font_8, 0, 256);
2625 sc->fonts_loaded = FONT_8;
2626 } else if (scp->font_size >= 16) {
2627 sc_save_font(scp, 0, 16, sc->font_16, 0, 256);
2628 sc->fonts_loaded = FONT_16;
2630 sc_save_font(scp, 0, 14, sc->font_14, 0, 256);
2631 sc->fonts_loaded = FONT_14;
2633 #endif /* SC_DFLT_FONT */
2634 /* FONT KLUDGE: always use the font page #0. XXX */
2635 sc_show_font(scp, 0);
2637 #endif /* !SC_NO_FONT_LOADING */
2639 #ifndef SC_NO_PALETTE_LOADING
2640 save_palette(sc->adp, sc->palette);
2644 if (!(sc->flags & SC_SPLASH_SCRN) && (flags & SC_KERNEL_CONSOLE)) {
2645 /* we are ready to put up the splash image! */
2646 splash_init(sc->adp, scsplash_callback, sc);
2647 sc->flags |= SC_SPLASH_SCRN;
2649 #endif /* NSPLASH */
2652 /* the rest is not necessary, if we have done it once */
2653 if (sc->flags & SC_INIT_DONE)
2656 /* initialize mapscrn arrays to a one to one map */
2657 for (i = 0; i < sizeof(sc->scr_map); i++)
2658 sc->scr_map[i] = sc->scr_rmap[i] = i;
2660 sc->flags |= SC_INIT_DONE;
2664 scterm(int unit, int flags)
2669 sc = sc_get_softc(unit, flags & SC_KERNEL_CONSOLE);
2671 return; /* shouldn't happen */
2674 /* this console is no longer available for the splash screen */
2675 if (sc->flags & SC_SPLASH_SCRN) {
2676 splash_term(sc->adp);
2677 sc->flags &= ~SC_SPLASH_SCRN;
2679 #endif /* NSPLASH */
2682 /* move the hardware cursor to the upper-left corner */
2683 (*vidsw[sc->adapter]->set_hw_cursor)(sc->adp, 0, 0);
2686 /* release the keyboard and the video card */
2687 if (sc->keyboard >= 0)
2688 kbd_release(sc->kbd, &sc->keyboard);
2689 if (sc->adapter >= 0)
2690 vid_release(sc->adp, &sc->adapter);
2693 * Stop the terminal emulator, if any. If operating on the
2694 * kernel console sc->dev may not be setup yet.
2696 if (flags & SC_KERNEL_CONSOLE)
2697 scp = sc->console_scp;
2699 scp = SC_STAT(sc->dev[0]);
2701 (*scp->tsw->te_term)(scp, &scp->ts);
2702 if (scp->ts != NULL)
2703 kfree(scp->ts, M_SYSCONS);
2705 /* clear the structure */
2706 if (!(flags & SC_KERNEL_CONSOLE)) {
2707 /* XXX: We need delete_dev() for this */
2708 kfree(sc->dev, M_SYSCONS);
2710 /* XXX: We need a ttyunregister for this */
2711 kfree(sc->tty, M_SYSCONS);
2713 #ifndef SC_NO_FONT_LOADING
2714 kfree(sc->font_8, M_SYSCONS);
2715 kfree(sc->font_14, M_SYSCONS);
2716 kfree(sc->font_16, M_SYSCONS);
2718 /* XXX vtb, history */
2720 bzero(sc, sizeof(*sc));
2726 scshutdown(void *arg, int howto)
2728 /* assert(sc_console != NULL) */
2730 sc_touch_scrn_saver();
2731 if (!cold && sc_console
2732 && sc_console->sc->cur_scp->smode.mode == VT_AUTO
2733 && sc_console->smode.mode == VT_AUTO)
2734 sc_switch_scr(sc_console->sc, sc_console->index);
2735 shutdown_in_progress = TRUE;
2739 sc_clean_up(scr_stat *scp)
2743 #endif /* NSPLASH */
2745 if (scp->sc->flags & SC_SCRN_BLANKED) {
2746 sc_touch_scrn_saver();
2748 if ((error = wait_scrn_saver_stop(scp->sc)))
2750 #endif /* NSPLASH */
2752 scp->status |= MOUSE_HIDDEN;
2753 sc_remove_mouse_image(scp);
2754 sc_remove_cutmarking(scp);
2759 sc_alloc_scr_buffer(scr_stat *scp, int wait, int discard)
2765 sc_vtb_init(&new, VTB_MEMORY, scp->xsize, scp->ysize, NULL, wait);
2766 if (!discard && (old.vtb_flags & VTB_VALID)) {
2767 /* retain the current cursor position and buffer contants */
2768 scp->cursor_oldpos = scp->cursor_pos;
2770 * This works only if the old buffer has the same size as or larger
2771 * than the new one. XXX
2773 sc_vtb_copy(&old, 0, &new, 0, scp->xsize*scp->ysize);
2777 sc_vtb_destroy(&old);
2780 #ifndef SC_NO_SYSMOUSE
2781 /* move the mouse cursor at the center of the screen */
2782 sc_mouse_move(scp, scp->xpixel / 2, scp->ypixel / 2);
2787 alloc_scp(sc_softc_t *sc, int vty)
2791 /* assert(sc_malloc) */
2793 scp = kmalloc(sizeof(scr_stat), M_SYSCONS, M_WAITOK);
2794 init_scp(sc, vty, scp);
2796 sc_alloc_scr_buffer(scp, TRUE, TRUE);
2797 if (sc_init_emulator(scp, SC_DFLT_TERM))
2798 sc_init_emulator(scp, "*");
2800 #ifndef SC_NO_CUTPASTE
2801 sc_alloc_cut_buffer(scp, TRUE);
2804 #ifndef SC_NO_HISTORY
2805 sc_alloc_history_buffer(scp, 0, 0, TRUE);
2812 init_scp(sc_softc_t *sc, int vty, scr_stat *scp)
2816 bzero(scp, sizeof(*scp));
2821 scp->mode = sc->initial_mode;
2822 callout_init(&scp->blink_screen_ch);
2823 (*vidsw[sc->adapter]->get_info)(sc->adp, scp->mode, &info);
2824 if (info.vi_flags & V_INFO_GRAPHICS) {
2825 scp->status |= GRAPHICS_MODE;
2826 scp->xpixel = info.vi_width;
2827 scp->ypixel = info.vi_height;
2828 scp->xsize = info.vi_width/8;
2829 scp->ysize = info.vi_height/info.vi_cheight;
2833 scp->xsize = info.vi_width;
2834 scp->ysize = info.vi_height;
2835 scp->xpixel = scp->xsize*8;
2836 scp->ypixel = scp->ysize*info.vi_cheight;
2837 if (info.vi_cheight < 14) {
2839 #ifndef SC_NO_FONT_LOADING
2840 scp->font = sc->font_8;
2844 } else if (info.vi_cheight >= 16) {
2845 scp->font_size = 16;
2846 #ifndef SC_NO_FONT_LOADING
2847 scp->font = sc->font_16;
2852 scp->font_size = 14;
2853 #ifndef SC_NO_FONT_LOADING
2854 scp->font = sc->font_14;
2860 sc_vtb_init(&scp->vtb, VTB_MEMORY, 0, 0, NULL, FALSE);
2861 sc_vtb_init(&scp->scr, VTB_FRAMEBUFFER, 0, 0, NULL, FALSE);
2862 scp->xoff = scp->yoff = 0;
2863 scp->xpos = scp->ypos = 0;
2864 scp->start = scp->xsize * scp->ysize - 1;
2869 scp->border = BG_BLACK;
2870 scp->cursor_base = sc->cursor_base;
2871 scp->cursor_height = imin(sc->cursor_height, scp->font_size);
2872 scp->mouse_cut_start = scp->xsize*scp->ysize;
2873 scp->mouse_cut_end = -1;
2874 scp->mouse_signal = 0;
2876 scp->mouse_proc = NULL;
2877 scp->kbd_mode = K_XLATE;
2878 scp->bell_pitch = bios_value.bell_pitch;
2879 scp->bell_duration = BELL_DURATION;
2880 scp->status |= (bios_value.shift_state & NLKED);
2881 scp->status |= CURSOR_ENABLED | MOUSE_HIDDEN;
2884 scp->smode.mode = VT_AUTO;
2885 scp->history = NULL;
2886 scp->history_pos = 0;
2887 scp->history_size = 0;
2891 sc_init_emulator(scr_stat *scp, char *name)
2898 if (name == NULL) /* if no name is given, use the current emulator */
2900 else /* ...otherwise find the named emulator */
2901 sw = sc_term_match(name);
2906 if (strcmp(sw->te_renderer, "*") != 0) {
2907 rndr = sc_render_match(scp, sw->te_renderer,
2908 scp->status & (GRAPHICS_MODE | PIXEL_MODE));
2911 rndr = sc_render_match(scp, scp->sc->adp->va_name,
2912 scp->status & (GRAPHICS_MODE | PIXEL_MODE));
2917 if (sw == scp->tsw) {
2918 error = (*sw->te_init)(scp, &scp->ts, SC_TE_WARM_INIT);
2920 scp->rndr->init(scp);
2921 sc_clear_screen(scp);
2922 /* assert(error == 0); */
2926 if (sc_malloc && (sw->te_size > 0))
2927 p = kmalloc(sw->te_size, M_SYSCONS, M_NOWAIT);
2930 error = (*sw->te_init)(scp, &p, SC_TE_COLD_INIT);
2935 (*scp->tsw->te_term)(scp, &scp->ts);
2936 if (scp->ts != NULL)
2937 kfree(scp->ts, M_SYSCONS);
2941 scp->rndr->init(scp);
2944 (*sw->te_default_attr)(scp, user_default.std_color, user_default.rev_color);
2945 sc_clear_screen(scp);
2951 * scgetc(flags) - get character from keyboard.
2952 * If flags & SCGETC_CN, then avoid harmful side effects.
2953 * If flags & SCGETC_NONBLOCK, then wait until a key is pressed, else
2954 * return NOKEY if there is nothing there.
2957 scgetc(sc_softc_t *sc, u_int flags)
2960 #ifndef SC_NO_HISTORY
2968 if (sc->kbd == NULL)
2973 /* I don't like this, but... XXX */
2974 if (flags & SCGETC_CN)
2975 sccnupdate(sc->cur_scp);
2978 /* first see if there is something in the keyboard port */
2980 c = kbd_read_char(sc->kbd, !(flags & SCGETC_NONBLOCK));
2982 if (!(flags & SCGETC_CN))
2983 sc_bell(scp, bios_value.bell_pitch, BELL_DURATION);
2984 } else if (c == NOKEY)
2990 /* make screensaver happy */
2992 sc_touch_scrn_saver();
2994 if (!(flags & SCGETC_CN))
2995 /* do the /dev/random device a favour */
2996 add_keyboard_randomness(c);
2998 if (scp->kbd_mode != K_XLATE)
3001 /* if scroll-lock pressed allow history browsing */
3002 if (!ISGRAPHSC(scp) && scp->history && scp->status & SLKED) {
3004 scp->status &= ~CURSOR_ENABLED;
3005 sc_remove_cursor_image(scp);
3007 #ifndef SC_NO_HISTORY
3008 if (!(scp->status & BUFFER_SAVED)) {
3009 scp->status |= BUFFER_SAVED;
3013 /* FIXME: key codes */
3014 case SPCLKEY | FKEY | F(49): /* home key */
3015 sc_remove_cutmarking(scp);
3019 case SPCLKEY | FKEY | F(57): /* end key */
3020 sc_remove_cutmarking(scp);
3024 case SPCLKEY | FKEY | F(50): /* up arrow key */
3025 sc_remove_cutmarking(scp);
3026 if (sc_hist_up_line(scp))
3027 if (!(flags & SCGETC_CN))
3028 sc_bell(scp, bios_value.bell_pitch, BELL_DURATION);
3031 case SPCLKEY | FKEY | F(58): /* down arrow key */
3032 sc_remove_cutmarking(scp);
3033 if (sc_hist_down_line(scp))
3034 if (!(flags & SCGETC_CN))
3035 sc_bell(scp, bios_value.bell_pitch, BELL_DURATION);
3038 case SPCLKEY | FKEY | F(51): /* page up key */
3039 sc_remove_cutmarking(scp);
3040 for (i=0; i<scp->ysize; i++)
3041 if (sc_hist_up_line(scp)) {
3042 if (!(flags & SCGETC_CN))
3043 sc_bell(scp, bios_value.bell_pitch, BELL_DURATION);
3048 case SPCLKEY | FKEY | F(59): /* page down key */
3049 sc_remove_cutmarking(scp);
3050 for (i=0; i<scp->ysize; i++)
3051 if (sc_hist_down_line(scp)) {
3052 if (!(flags & SCGETC_CN))
3053 sc_bell(scp, bios_value.bell_pitch, BELL_DURATION);
3058 #endif /* SC_NO_HISTORY */
3062 * Process and consume special keys here. Return a plain char code
3063 * or a char code with the META flag or a function key code.
3067 /* goto next_code */
3072 switch (KEYCHAR(c)) {
3074 case NLK: case CLK: case ALK:
3077 kbd_ioctl(sc->kbd, KDGKBSTATE, (caddr_t)&f);
3079 scp->status |= SLKED;
3081 if (scp->status & SLKED) {
3082 scp->status &= ~SLKED;
3083 #ifndef SC_NO_HISTORY
3084 if (scp->status & BUFFER_SAVED) {
3085 if (!sc_hist_restore(scp))
3086 sc_remove_cutmarking(scp);
3087 scp->status &= ~BUFFER_SAVED;
3088 scp->status |= CURSOR_ENABLED;
3089 sc_draw_cursor_image(scp);
3091 tp = VIRTUAL_TTY(sc, scp->index);
3099 /* NON-LOCKING KEYS */
3101 case LSH: case RSH: case LCTR: case RCTR:
3102 case LALT: case RALT: case ASH: case META:
3106 if (!(sc->flags & SC_SCRN_BLANKED))
3112 /* force activatation/deactivation of the screen saver */
3113 if (!(sc->flags & SC_SCRN_BLANKED)) {
3114 run_scrn_saver = TRUE;
3115 sc->scrn_time_stamp -= scrn_blank_time;
3119 * While devices are being probed, the screen saver need
3120 * to be invoked explictly. XXX
3122 if (sc->flags & SC_SCRN_BLANKED) {
3123 scsplash_stick(FALSE);
3124 stop_scrn_saver(sc, current_saver);
3126 if (!ISGRAPHSC(scp)) {
3127 scsplash_stick(TRUE);
3128 (*current_saver)(sc, TRUE);
3132 #endif /* NSPLASH */
3136 #ifndef SC_DISABLE_REBOOT
3142 #ifndef SC_DISABLE_REBOOT
3143 shutdown_nice(RB_HALT);
3148 #ifndef SC_DISABLE_REBOOT
3149 shutdown_nice(RB_HALT|RB_POWEROFF);
3155 apm_suspend(PMST_SUSPEND);
3158 apm_suspend(PMST_STANDBY);
3167 #ifndef SC_DISABLE_DDBKEY
3169 Debugger("manual escape to debugger");
3171 kprintf("No debugger in kernel\n");
3173 #else /* SC_DISABLE_DDBKEY */
3175 #endif /* SC_DISABLE_DDBKEY */
3179 if (enable_panic_key)
3180 panic("Forced by the panic key");
3184 this_scr = scp->index;
3185 for (i = (this_scr - sc->first_vty + 1)%sc->vtys;
3186 sc->first_vty + i != this_scr;
3187 i = (i + 1)%sc->vtys) {
3188 struct tty *tp = VIRTUAL_TTY(sc, sc->first_vty + i);
3189 if (ISTTYOPEN(tp)) {
3190 sc_switch_scr(scp->sc, sc->first_vty + i);
3197 this_scr = scp->index;
3198 for (i = (this_scr - sc->first_vty + sc->vtys - 1)%sc->vtys;
3199 sc->first_vty + i != this_scr;
3200 i = (i + sc->vtys - 1)%sc->vtys) {
3201 struct tty *tp = VIRTUAL_TTY(sc, sc->first_vty + i);
3202 if (ISTTYOPEN(tp)) {
3203 sc_switch_scr(scp->sc, sc->first_vty + i);
3210 if (KEYCHAR(c) >= F_SCR && KEYCHAR(c) <= L_SCR) {
3211 sc_switch_scr(scp->sc, sc->first_vty + KEYCHAR(c) - F_SCR);
3214 /* assert(c & FKEY) */
3215 if (!(sc->flags & SC_SCRN_BLANKED))
3219 /* goto next_code */
3221 /* regular keys (maybe MKEY is set) */
3222 if (!(sc->flags & SC_SCRN_BLANKED))
3231 scmmap(struct dev_mmap_args *ap)
3235 scp = SC_STAT(ap->a_head.a_dev);
3236 if (scp != scp->sc->cur_scp)
3238 ap->a_result = (*vidsw[scp->sc->adapter]->mmap)(scp->sc->adp, ap->a_offset,
3244 save_kbd_state(scr_stat *scp)
3249 error = kbd_ioctl(scp->sc->kbd, KDGKBSTATE, (caddr_t)&state);
3250 if (error == ENOIOCTL)
3253 scp->status &= ~LOCK_MASK;
3254 scp->status |= state;
3260 update_kbd_state(scr_stat *scp, int new_bits, int mask)
3265 if (mask != LOCK_MASK) {
3266 error = kbd_ioctl(scp->sc->kbd, KDGKBSTATE, (caddr_t)&state);
3267 if (error == ENOIOCTL)
3272 state |= new_bits & mask;
3274 state = new_bits & LOCK_MASK;
3276 error = kbd_ioctl(scp->sc->kbd, KDSKBSTATE, (caddr_t)&state);
3277 if (error == ENOIOCTL)
3283 update_kbd_leds(scr_stat *scp, int which)
3288 error = kbd_ioctl(scp->sc->kbd, KDSETLED, (caddr_t)&which);
3289 if (error == ENOIOCTL)
3295 set_mode(scr_stat *scp)
3299 /* reject unsupported mode */
3300 if ((*vidsw[scp->sc->adapter]->get_info)(scp->sc->adp, scp->mode, &info))
3303 /* if this vty is not currently showing, do nothing */
3304 if (scp != scp->sc->cur_scp)
3307 /* setup video hardware for the given mode */
3308 (*vidsw[scp->sc->adapter]->set_mode)(scp->sc->adp, scp->mode);
3309 scp->rndr->init(scp);
3310 sc_vtb_init(&scp->scr, VTB_FRAMEBUFFER, scp->xsize, scp->ysize,
3311 (void *)scp->sc->adp->va_window, FALSE);
3313 #ifndef SC_NO_FONT_LOADING
3314 /* load appropriate font */
3315 if (!(scp->status & GRAPHICS_MODE)) {
3316 if (!(scp->status & PIXEL_MODE) && ISFONTAVAIL(scp->sc->adp->va_flags)) {
3317 if (scp->font_size < 14) {
3318 if (scp->sc->fonts_loaded & FONT_8)
3319 sc_load_font(scp, 0, 8, scp->sc->font_8, 0, 256);
3320 } else if (scp->font_size >= 16) {
3321 if (scp->sc->fonts_loaded & FONT_16)
3322 sc_load_font(scp, 0, 16, scp->sc->font_16, 0, 256);
3324 if (scp->sc->fonts_loaded & FONT_14)
3325 sc_load_font(scp, 0, 14, scp->sc->font_14, 0, 256);
3329 * This is an interim kludge to display correct font.
3330 * Always use the font page #0 on the video plane 2.
3331 * Somehow we cannot show the font in other font pages on
3332 * some video cards... XXX
3334 sc_show_font(scp, 0);
3338 #endif /* !SC_NO_FONT_LOADING */
3340 sc_set_border(scp, scp->border);
3341 sc_set_cursor_image(scp);
3347 refresh_ega_palette(scr_stat *scp)
3351 int rsize, gsize, bsize;
3352 int rfld, gfld, bfld;
3355 rsize = scp->sc->adp->va_info.vi_pixel_fsizes[0];
3356 gsize = scp->sc->adp->va_info.vi_pixel_fsizes[1];
3357 bsize = scp->sc->adp->va_info.vi_pixel_fsizes[2];
3358 rfld = scp->sc->adp->va_info.vi_pixel_fields[0];
3359 gfld = scp->sc->adp->va_info.vi_pixel_fields[1];
3360 bfld = scp->sc->adp->va_info.vi_pixel_fields[2];
3362 for (i = 0; i < 16; i++) {
3363 reg = scp->sc->adp->va_palette_regs[i];
3365 r = scp->sc->palette[reg * 3] >> (8 - rsize);
3366 g = scp->sc->palette[reg * 3 + 1] >> (8 - gsize);
3367 b = scp->sc->palette[reg * 3 + 2] >> (8 - bsize);
3369 scp->ega_palette[i] = (r << rfld) + (g << gfld) + (b << bfld);
3374 sc_set_border(scr_stat *scp, int color)
3376 ++scp->sc->videoio_in_progress;
3377 (*scp->rndr->draw_border)(scp, color);
3378 --scp->sc->videoio_in_progress;
3381 #ifndef SC_NO_FONT_LOADING
3383 sc_load_font(scr_stat *scp, int page, int size, u_char *buf,
3384 int base, int count)
3389 sc->font_loading_in_progress = TRUE;
3390 (*vidsw[sc->adapter]->load_font)(sc->adp, page, size, buf, base, count);
3391 sc->font_loading_in_progress = FALSE;
3395 sc_save_font(scr_stat *scp, int page, int size, u_char *buf,
3396 int base, int count)
3401 sc->font_loading_in_progress = TRUE;
3402 (*vidsw[sc->adapter]->save_font)(sc->adp, page, size, buf, base, count);
3403 sc->font_loading_in_progress = FALSE;
3407 sc_show_font(scr_stat *scp, int page)
3409 (*vidsw[scp->sc->adapter]->show_font)(scp->sc->adp, page);
3411 #endif /* !SC_NO_FONT_LOADING */
3414 sc_paste(scr_stat *scp, u_char *p, int count)
3419 if (scp->status & MOUSE_VISIBLE) {
3420 tp = VIRTUAL_TTY(scp->sc, scp->sc->cur_scp->index);
3423 rmap = scp->sc->scr_rmap;
3424 for (; count > 0; --count)
3425 (*linesw[tp->t_line].l_rint)(rmap[*p++], tp);
3430 sc_bell(scr_stat *scp, int pitch, int duration)
3432 if (cold || shutdown_in_progress)
3435 if (scp != scp->sc->cur_scp && (scp->sc->flags & SC_QUIET_BELL))
3438 if (scp->sc->flags & SC_VISUAL_BELL) {
3439 if (scp->sc->blink_in_progress)
3441 scp->sc->blink_in_progress = 3;
3442 if (scp != scp->sc->cur_scp)
3443 scp->sc->blink_in_progress += 2;
3444 blink_screen(scp->sc->cur_scp);
3445 } else if (duration != 0 && pitch != 0) {
3446 if (scp != scp->sc->cur_scp)
3448 sysbeep(pitch, duration);
3453 blink_screen(void *arg)
3455 scr_stat *scp = arg;
3458 if (ISGRAPHSC(scp) || (scp->sc->blink_in_progress <= 1)) {
3459 scp->sc->blink_in_progress = 0;
3461 tp = VIRTUAL_TTY(scp->sc, scp->index);
3464 if (scp->sc->delayed_next_scr)
3465 sc_switch_scr(scp->sc, scp->sc->delayed_next_scr - 1);
3468 (*scp->rndr->draw)(scp, 0, scp->xsize*scp->ysize,
3469 scp->sc->blink_in_progress & 1);
3470 scp->sc->blink_in_progress--;
3471 callout_reset(&scp->blink_screen_ch, hz / 10, blink_screen, scp);