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.18 2005/02/18 16:38:23 swildner Exp $
35 #include "use_splash.h"
36 #include "opt_syscons.h"
40 #include <sys/param.h>
41 #include <sys/systm.h>
42 #include <sys/eventhandler.h>
43 #include <sys/reboot.h>
46 #include <sys/signalvar.h>
47 #include <sys/sysctl.h>
49 #include <sys/kernel.h>
50 #include <sys/malloc.h>
52 #include <sys/random.h>
54 #include <machine/clock.h>
55 #include <machine/console.h>
56 #include <machine/psl.h>
57 #include <machine/pc/display.h>
58 #include <machine/apm_bios.h>
59 #include <machine/frame.h>
61 #include <dev/misc/kbd/kbdreg.h>
62 #include <dev/video/fb/fbreg.h>
63 #include <dev/video/fb/splashreg.h>
69 #define DEFAULT_BLANKTIME (5*60) /* 5 minutes */
70 #define MAX_BLANKTIME (7*24*60*60) /* 7 days!? */
72 #define KEYCODE_BS 0x0e /* "<-- Backspace" key, XXX */
74 typedef struct default_attr {
75 int std_color; /* normal hardware color */
76 int rev_color; /* reverse hardware color */
79 static default_attr user_default = {
84 static default_attr kernel_default = {
86 SC_KERNEL_CONS_REV_ATTR,
89 static int sc_console_unit = -1;
90 static scr_stat *sc_console;
91 static struct tty *sc_console_tty;
92 static void *kernel_console_ts;
94 static char init_done = COLD;
95 static char shutdown_in_progress = FALSE;
96 static char sc_malloc = FALSE;
98 static int saver_mode = CONS_NO_SAVER; /* LKM/user saver */
99 static int run_scrn_saver = FALSE; /* should run the saver? */
100 static long scrn_blank_time = 0; /* screen saver timeout value */
102 static int scrn_blanked; /* # of blanked screen */
103 static int sticky_splash = FALSE;
105 static void none_saver(sc_softc_t *sc, int blank) { }
106 static void (*current_saver)(sc_softc_t *, int) = none_saver;
109 #if !defined(SC_NO_FONT_LOADING) && defined(SC_DFLT_FONT)
113 d_ioctl_t *sc_user_ioctl;
115 static bios_values_t bios_value;
117 static int enable_panic_key;
118 SYSCTL_INT(_machdep, OID_AUTO, enable_panic_key, CTLFLAG_RW, &enable_panic_key,
121 #define SC_CONSOLECTL 255
123 #define VIRTUAL_TTY(sc, x) (SC_DEV((sc), (x)) != NULL ? \
124 SC_DEV((sc), (x))->si_tty : NULL)
125 #define ISTTYOPEN(tp) ((tp) && ((tp)->t_state & TS_ISOPEN))
130 static int scvidprobe(int unit, int flags, int cons);
131 static int sckbdprobe(int unit, int flags, int cons);
132 static void scmeminit(void *arg);
133 static int scdevtounit(dev_t dev);
134 static kbd_callback_func_t sckbdevent;
135 static int scparam(struct tty *tp, struct termios *t);
136 static void scstart(struct tty *tp);
137 static void scinit(int unit, int flags);
138 static void scterm(int unit, int flags);
139 static void scshutdown(void *arg, int howto);
140 static u_int scgetc(sc_softc_t *sc, u_int flags);
142 #define SCGETC_NONBLOCK 2
143 static int sccngetch(int flags);
144 static void sccnupdate(scr_stat *scp);
145 static scr_stat *alloc_scp(sc_softc_t *sc, int vty);
146 static void init_scp(sc_softc_t *sc, int vty, scr_stat *scp);
147 static timeout_t scrn_timer;
148 static int and_region(int *s1, int *e1, int s2, int e2);
149 static void scrn_update(scr_stat *scp, int show_cursor);
152 static int scsplash_callback(int event, void *arg);
153 static void scsplash_saver(sc_softc_t *sc, int show);
154 static int add_scrn_saver(void (*this_saver)(sc_softc_t *, int));
155 static int remove_scrn_saver(void (*this_saver)(sc_softc_t *, int));
156 static int set_scrn_saver_mode(scr_stat *scp, int mode, u_char *pal, int border);
157 static int restore_scrn_saver_mode(scr_stat *scp, int changemode);
158 static void stop_scrn_saver(sc_softc_t *sc, void (*saver)(sc_softc_t *, int));
159 static int wait_scrn_saver_stop(sc_softc_t *sc);
160 #define scsplash_stick(stick) (sticky_splash = (stick))
162 #define scsplash_stick(stick)
165 static int do_switch_scr(sc_softc_t *sc, int s);
166 static int vt_proc_alive(scr_stat *scp);
167 static int signal_vt_rel(scr_stat *scp);
168 static int signal_vt_acq(scr_stat *scp);
169 static int finish_vt_rel(scr_stat *scp, int release, int *s);
170 static int finish_vt_acq(scr_stat *scp);
171 static void exchange_scr(sc_softc_t *sc);
172 static void update_cursor_image(scr_stat *scp);
173 static int save_kbd_state(scr_stat *scp);
174 static int update_kbd_state(scr_stat *scp, int state, int mask);
175 static int update_kbd_leds(scr_stat *scp, int which);
176 static timeout_t blink_screen;
178 #define CDEV_MAJOR 12
180 static cn_probe_t sccnprobe;
181 static cn_init_t sccninit;
182 static cn_getc_t sccngetc;
183 static cn_checkc_t sccncheckc;
184 static cn_putc_t sccnputc;
185 static cn_dbctl_t sccndbctl;
186 static cn_term_t sccnterm;
188 CONS_DRIVER(sc, sccnprobe, sccninit, sccnterm, sccngetc, sccncheckc, sccnputc,
191 static d_open_t scopen;
192 static d_close_t scclose;
193 static d_read_t scread;
194 static d_ioctl_t scioctl;
195 static d_mmap_t scmmap;
197 static struct cdevsw sc_cdevsw = {
199 /* maj */ CDEV_MAJOR,
200 /* flags */ D_TTY | D_KQFILTER,
207 /* write */ ttywrite,
211 /* strategy */ nostrategy,
214 /* kqfilter */ ttykqfilter
218 sc_probe_unit(int unit, int flags)
220 if (!scvidprobe(unit, flags, FALSE)) {
222 printf("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 = malloc(sc_console->tsw->te_size,
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);
321 callout_init(&sc->scrn_timer_ch);
322 scp = SC_STAT(sc->dev[0]);
323 if (sc_console == NULL) /* sc_console_unit < 0 */
327 if ((sc->config & SC_VESA800X600)
328 && ((*vidsw[sc->adapter]->get_info)(sc->adp, M_VESA_800x600, &info) == 0)) {
330 if (sc->flags & SC_SPLASH_SCRN)
331 splash_term(sc->adp);
333 sc_set_graphics_mode(scp, NULL, M_VESA_800x600);
334 sc_set_pixel_mode(scp, NULL, COL, ROW, 16);
335 sc->initial_mode = M_VESA_800x600;
337 /* put up the splash again! */
338 if (sc->flags & SC_SPLASH_SCRN)
339 splash_init(sc->adp, scsplash_callback, sc);
342 #endif /* SC_PIXEL_MODE */
344 /* initialize cursor */
346 update_cursor_image(scp);
348 /* get screen update going */
351 /* set up the keyboard */
352 kbd_ioctl(sc->kbd, KDSKBMODE, (caddr_t)&scp->kbd_mode);
353 update_kbd_state(scp, scp->status, LOCK_MASK);
355 printf("sc%d: %s <%d virtual consoles, flags=0x%x>\n",
356 unit, adapter_name(sc->adp), sc->vtys, sc->config);
358 printf("sc%d:", unit);
359 if (sc->adapter >= 0)
360 printf(" fb%d", sc->adapter);
361 if (sc->keyboard >= 0)
362 printf(", kbd%d", sc->keyboard);
364 printf(", terminal emulator: %s (%s)",
365 scp->tsw->te_name, scp->tsw->te_desc);
369 /* register a shutdown callback for the kernel console */
370 if (sc_console_unit == unit)
371 EVENTHANDLER_REGISTER(shutdown_pre_sync, scshutdown,
372 (void *)(uintptr_t)unit, SHUTDOWN_PRI_DEFAULT);
375 * create devices. cdevsw_add() must be called to make devices under
376 * this major number available to userland.
378 cdevsw_add(&sc_cdevsw, ~(MAXCONS - 1), unit * MAXCONS);
380 for (vc = 0; vc < sc->vtys; vc++) {
381 dev = make_dev(&sc_cdevsw, vc + unit * MAXCONS,
382 UID_ROOT, GID_WHEEL, 0600, "ttyv%r", vc + unit * MAXCONS);
385 * The first vty already has struct tty and scr_stat initialized
386 * in scinit(). The other vtys will have these structs when
391 cdevsw_add(&sc_cdevsw, -1, SC_CONSOLECTL); /* XXX */
392 dev = make_dev(&sc_cdevsw, SC_CONSOLECTL,
393 UID_ROOT, GID_WHEEL, 0600, "consolectl");
394 dev->si_tty = sc_console_tty = ttymalloc(sc_console_tty);
395 dev->si_drv1 = sc_console;
408 * As soon as malloc() becomes functional, we had better allocate
409 * various buffers for the kernel console.
412 if (sc_console_unit < 0) /* sc_console == NULL */
415 /* copy the temporary buffer to the final buffer */
416 sc_alloc_scr_buffer(sc_console, TRUE, FALSE);
418 #ifndef SC_NO_CUTPASTE
419 sc_alloc_cut_buffer(sc_console, TRUE);
422 #ifndef SC_NO_HISTORY
423 /* initialize history buffer & pointers */
424 sc_alloc_history_buffer(sc_console, 0, 0, TRUE);
429 SYSINIT(sc_mem, SI_SUB_KMEM, SI_ORDER_ANY, scmeminit, NULL);
432 scdevtounit(dev_t dev)
434 int vty = SC_VTY(dev);
436 if (vty == SC_CONSOLECTL)
437 return ((sc_console != NULL) ? sc_console->sc->unit : -1);
438 else if ((vty < 0) || (vty >= MAXCONS*sc_max_unit()))
445 scopen(dev_t dev, int flag, int mode, struct thread *td)
447 int unit = scdevtounit(dev);
454 DPRINTF(5, ("scopen: dev:%d,%d, unit:%d, vty:%d\n",
455 major(dev), minor(dev), unit, SC_VTY(dev)));
457 sc = sc_get_softc(unit, (sc_console_unit == unit) ? SC_KERNEL_CONSOLE : 0);
461 tp = dev->si_tty = ttymalloc(dev->si_tty);
462 tp->t_oproc = scstart;
463 tp->t_param = scparam;
464 tp->t_stop = nottystop;
466 if (!ISTTYOPEN(tp)) {
468 /* Use the current setting of the <-- key as default VERASE. */
469 /* If the Delete key is preferable, an stty is necessary */
470 if (sc->kbd != NULL) {
471 key.keynum = KEYCODE_BS;
472 kbd_ioctl(sc->kbd, GIO_KEYMAPENT, (caddr_t)&key);
473 tp->t_cc[VERASE] = key.key.map[0];
475 tp->t_iflag = TTYDEF_IFLAG;
476 tp->t_oflag = TTYDEF_OFLAG;
477 tp->t_cflag = TTYDEF_CFLAG;
478 tp->t_lflag = TTYDEF_LFLAG;
479 tp->t_ispeed = tp->t_ospeed = TTYDEF_SPEED;
480 scparam(tp, &tp->t_termios);
481 (*linesw[tp->t_line].l_modem)(tp, 1);
484 if (tp->t_state & TS_XCLUDE && suser(td))
487 error = (*linesw[tp->t_line].l_open)(dev, tp);
491 scp = dev->si_drv1 = alloc_scp(sc, SC_VTY(dev));
493 sc_set_pixel_mode(scp, NULL, COL, ROW, 16);
495 if (!tp->t_winsize.ws_col && !tp->t_winsize.ws_row) {
496 tp->t_winsize.ws_col = scp->xsize;
497 tp->t_winsize.ws_row = scp->ysize;
504 scclose(dev_t dev, int flag, int mode, struct thread *td)
506 struct tty *tp = dev->si_tty;
510 if (SC_VTY(dev) != SC_CONSOLECTL) {
511 scp = SC_STAT(tp->t_dev);
512 /* were we in the middle of the VT switching process? */
513 DPRINTF(5, ("sc%d: scclose(), ", scp->sc->unit));
515 if ((scp == scp->sc->cur_scp) && (scp->sc->unit == sc_console_unit))
516 cons_unavail = FALSE;
517 if (finish_vt_rel(scp, TRUE, &s) == 0) /* force release */
518 DPRINTF(5, ("reset WAIT_REL, "));
519 if (finish_vt_acq(scp) == 0) /* force acknowledge */
520 DPRINTF(5, ("reset WAIT_ACQ, "));
522 if (scp == &main_console) {
525 scp->smode.mode = VT_AUTO;
528 sc_vtb_destroy(&scp->vtb);
529 sc_vtb_destroy(&scp->scr);
530 sc_free_history_buffer(scp, scp->ysize);
537 scp->smode.mode = VT_AUTO;
539 scp->kbd_mode = K_XLATE;
540 if (scp == scp->sc->cur_scp)
541 kbd_ioctl(scp->sc->kbd, KDSKBMODE, (caddr_t)&scp->kbd_mode);
542 DPRINTF(5, ("done.\n"));
545 (*linesw[tp->t_line].l_close)(tp, flag);
552 scread(dev_t dev, struct uio *uio, int flag)
554 sc_touch_scrn_saver();
555 return ttyread(dev, uio, flag);
559 sckbdevent(keyboard_t *thiskbd, int event, void *arg)
567 sc = (sc_softc_t *)arg;
568 /* assert(thiskbd == sc->kbd) */
573 case KBDIO_UNLOADING:
576 kbd_release(thiskbd, (void *)&sc->keyboard);
583 * Loop while there is still input to get from the keyboard.
584 * I don't think this is nessesary, and it doesn't fix
585 * the Xaccel-2.1 keyboard hang, but it can't hurt. XXX
587 while ((c = scgetc(sc, SCGETC_NONBLOCK)) != NOKEY) {
589 cur_tty = VIRTUAL_TTY(sc, sc->cur_scp->index);
590 if (!ISTTYOPEN(cur_tty)) {
591 cur_tty = sc_console_tty;
592 if (!ISTTYOPEN(cur_tty))
596 if ((*sc->cur_scp->tsw->te_input)(sc->cur_scp, c, cur_tty))
599 switch (KEYFLAGS(c)) {
600 case 0x0000: /* normal key */
601 (*linesw[cur_tty->t_line].l_rint)(KEYCHAR(c), cur_tty);
603 case FKEY: /* function key, return string */
604 cp = kbd_get_fkeystr(thiskbd, KEYCHAR(c), &len);
607 (*linesw[cur_tty->t_line].l_rint)(*cp++, cur_tty);
610 case MKEY: /* meta is active, prepend ESC */
611 (*linesw[cur_tty->t_line].l_rint)(0x1b, cur_tty);
612 (*linesw[cur_tty->t_line].l_rint)(KEYCHAR(c), cur_tty);
614 case BKEY: /* backtab fixed sequence (esc [ Z) */
615 (*linesw[cur_tty->t_line].l_rint)(0x1b, cur_tty);
616 (*linesw[cur_tty->t_line].l_rint)('[', cur_tty);
617 (*linesw[cur_tty->t_line].l_rint)('Z', cur_tty);
622 sc->cur_scp->status |= MOUSE_HIDDEN;
628 scparam(struct tty *tp, struct termios *t)
630 tp->t_ispeed = t->c_ispeed;
631 tp->t_ospeed = t->c_ospeed;
632 tp->t_cflag = t->c_cflag;
637 scioctl(dev_t dev, u_long cmd, caddr_t data, int flag, struct thread *td)
645 struct proc *p = td->td_proc;
651 /* If there is a user_ioctl function call that first */
653 error = (*sc_user_ioctl)(dev, cmd, data, flag, td);
654 if (error != ENOIOCTL)
658 error = sc_vid_ioctl(tp, cmd, data, flag, td);
659 if (error != ENOIOCTL)
662 #ifndef SC_NO_HISTORY
663 error = sc_hist_ioctl(tp, cmd, data, flag, td);
664 if (error != ENOIOCTL)
668 #ifndef SC_NO_SYSMOUSE
669 error = sc_mouse_ioctl(tp, cmd, data, flag, td);
670 if (error != ENOIOCTL)
674 scp = SC_STAT(tp->t_dev);
675 /* assert(scp != NULL) */
676 /* scp is sc_console, if SC_VTY(dev) == SC_CONSOLECTL. */
680 error = (*scp->tsw->te_ioctl)(scp, tp, cmd, data, flag, td);
681 if (error != ENOIOCTL)
685 switch (cmd) { /* process console hardware related ioctl's */
687 case GIO_ATTR: /* get current attributes */
688 /* this ioctl is not processed here, but in the terminal emulator */
691 case GIO_COLOR: /* is this a color console ? */
692 *(int *)data = (sc->adp->va_flags & V_ADP_COLOR) ? 1 : 0;
695 case CONS_BLANKTIME: /* set screen saver timeout (0 = no saver) */
696 if (*(int *)data < 0 || *(int *)data > MAX_BLANKTIME)
699 scrn_blank_time = *(int *)data;
700 run_scrn_saver = (scrn_blank_time != 0);
704 case CONS_CURSORTYPE: /* set cursor type blink/noblink */
706 if (!ISGRAPHSC(sc->cur_scp))
707 sc_remove_cursor_image(sc->cur_scp);
708 if ((*(int*)data) & 0x01)
709 sc->flags |= SC_BLINK_CURSOR;
711 sc->flags &= ~SC_BLINK_CURSOR;
712 if ((*(int*)data) & 0x02) {
713 sc->flags |= SC_CHAR_CURSOR;
715 sc->flags &= ~SC_CHAR_CURSOR;
717 * The cursor shape is global property; all virtual consoles
718 * are affected. Update the cursor in the current console...
720 if (!ISGRAPHSC(sc->cur_scp)) {
721 sc_set_cursor_image(sc->cur_scp);
722 sc_draw_cursor_image(sc->cur_scp);
727 case CONS_BELLTYPE: /* set bell type sound/visual */
728 if ((*(int *)data) & 0x01)
729 sc->flags |= SC_VISUAL_BELL;
731 sc->flags &= ~SC_VISUAL_BELL;
732 if ((*(int *)data) & 0x02)
733 sc->flags |= SC_QUIET_BELL;
735 sc->flags &= ~SC_QUIET_BELL;
738 case CONS_GETINFO: /* get current (virtual) console info */
740 vid_info_t *ptr = (vid_info_t*)data;
741 if (ptr->size == sizeof(struct vid_info)) {
742 ptr->m_num = sc->cur_scp->index;
743 ptr->font_size = scp->font_size;
744 ptr->mv_col = scp->xpos;
745 ptr->mv_row = scp->ypos;
746 ptr->mv_csz = scp->xsize;
747 ptr->mv_rsz = scp->ysize;
749 * The following fields are filled by the terminal emulator. XXX
756 ptr->mv_grfc.fore = 0; /* not supported */
757 ptr->mv_grfc.back = 0; /* not supported */
758 ptr->mv_ovscan = scp->border;
759 if (scp == sc->cur_scp)
761 ptr->mk_keylock = scp->status & LOCK_MASK;
767 case CONS_GETVERS: /* get version number */
768 *(int*)data = 0x200; /* version 2.0 */
771 case CONS_IDLE: /* see if the screen has been idle */
773 * When the screen is in the GRAPHICS_MODE or UNKNOWN_MODE,
774 * the user process may have been writing something on the
775 * screen and syscons is not aware of it. Declare the screen
776 * is NOT idle if it is in one of these modes. But there is
777 * an exception to it; if a screen saver is running in the
778 * graphics mode in the current screen, we should say that the
779 * screen has been idle.
781 *(int *)data = (sc->flags & SC_SCRN_IDLE)
782 && (!ISGRAPHSC(sc->cur_scp)
783 || (sc->cur_scp->status & SAVER_RUNNING));
786 case CONS_SAVERMODE: /* set saver mode */
787 switch(*(int *)data) {
790 /* if a LKM screen saver is running, stop it first. */
791 scsplash_stick(FALSE);
792 saver_mode = *(int *)data;
795 if ((error = wait_scrn_saver_stop(NULL))) {
800 run_scrn_saver = TRUE;
801 if (saver_mode == CONS_USR_SAVER)
802 scp->status |= SAVER_RUNNING;
804 scp->status &= ~SAVER_RUNNING;
805 scsplash_stick(TRUE);
810 if ((saver_mode == CONS_USR_SAVER) && (scp->status & SAVER_RUNNING))
811 scp->status &= ~SAVER_RUNNING;
812 saver_mode = *(int *)data;
820 case CONS_SAVERSTART: /* immediately start/stop the screen saver */
822 * Note that this ioctl does not guarantee the screen saver
823 * actually starts or stops. It merely attempts to do so...
826 run_scrn_saver = (*(int *)data != 0);
828 sc->scrn_time_stamp -= scrn_blank_time;
832 case CONS_SCRSHOT: /* get a screen shot */
834 scrshot_t *ptr = (scrshot_t*)data;
836 if (ISGRAPHSC(scp)) {
840 if (scp->xsize != ptr->xsize || scp->ysize != ptr->ysize) {
844 copyout ((void*)scp->vtb.vtb_buffer, ptr->buf,
845 ptr->xsize * ptr->ysize * sizeof(u_int16_t));
850 case VT_SETMODE: /* set screen switcher mode */
852 struct vt_mode *mode;
854 mode = (struct vt_mode *)data;
855 DPRINTF(5, ("sc%d: VT_SETMODE ", sc->unit));
856 if (scp->smode.mode == VT_PROCESS) {
857 if (scp->proc == pfind(scp->pid) && scp->proc != p) {
858 DPRINTF(5, ("error EPERM\n"));
863 if (mode->mode == VT_AUTO) {
864 scp->smode.mode = VT_AUTO;
867 DPRINTF(5, ("VT_AUTO, "));
868 if ((scp == sc->cur_scp) && (sc->unit == sc_console_unit))
869 cons_unavail = FALSE;
870 /* were we in the middle of the vty switching process? */
871 if (finish_vt_rel(scp, TRUE, &s) == 0)
872 DPRINTF(5, ("reset WAIT_REL, "));
873 if (finish_vt_acq(scp) == 0)
874 DPRINTF(5, ("reset WAIT_ACQ, "));
876 if (!ISSIGVALID(mode->relsig) || !ISSIGVALID(mode->acqsig)
877 || !ISSIGVALID(mode->frsig)) {
879 DPRINTF(5, ("error EINVAL\n"));
882 DPRINTF(5, ("VT_PROCESS %d, ", p->p_pid));
883 bcopy(data, &scp->smode, sizeof(struct vt_mode));
885 scp->pid = scp->proc->p_pid;
886 if ((scp == sc->cur_scp) && (sc->unit == sc_console_unit))
894 case VT_GETMODE: /* get screen switcher mode */
895 bcopy(&scp->smode, data, sizeof(struct vt_mode));
898 case VT_RELDISP: /* screen switcher ioctl */
901 * This must be the current vty which is in the VT_PROCESS
904 if ((scp != sc->cur_scp) || (scp->smode.mode != VT_PROCESS)) {
908 /* ...and this process is controlling it. */
909 if (scp->proc != p) {
914 switch(*(int *)data) {
915 case VT_FALSE: /* user refuses to release screen, abort */
916 if ((error = finish_vt_rel(scp, FALSE, &s)) == 0)
917 DPRINTF(5, ("sc%d: VT_FALSE\n", sc->unit));
919 case VT_TRUE: /* user has released screen, go on */
920 if ((error = finish_vt_rel(scp, TRUE, &s)) == 0)
921 DPRINTF(5, ("sc%d: VT_TRUE\n", sc->unit));
923 case VT_ACKACQ: /* acquire acknowledged, switch completed */
924 if ((error = finish_vt_acq(scp)) == 0)
925 DPRINTF(5, ("sc%d: VT_ACKACQ\n", sc->unit));
933 case VT_OPENQRY: /* return free virtual console */
934 for (i = sc->first_vty; i < sc->first_vty + sc->vtys; i++) {
935 tp = VIRTUAL_TTY(sc, i);
936 if (!ISTTYOPEN(tp)) {
937 *(int *)data = i + 1;
943 case VT_ACTIVATE: /* switch to screen *data */
944 i = (*(int *)data == 0) ? scp->index : (*(int *)data - 1);
946 sc_clean_up(sc->cur_scp);
948 return sc_switch_scr(sc, i);
950 case VT_WAITACTIVE: /* wait for switch to occur */
951 i = (*(int *)data == 0) ? scp->index : (*(int *)data - 1);
952 if ((i < sc->first_vty) || (i >= sc->first_vty + sc->vtys))
955 error = sc_clean_up(sc->cur_scp);
959 scp = SC_STAT(SC_DEV(sc, i));
960 if (scp == scp->sc->cur_scp)
962 while ((error=tsleep((caddr_t)&scp->smode, PCATCH,
963 "waitvt", 0)) == ERESTART) ;
966 case VT_GETACTIVE: /* get active vty # */
967 *(int *)data = sc->cur_scp->index + 1;
970 case VT_GETINDEX: /* get this vty # */
971 *(int *)data = scp->index + 1;
974 case VT_LOCKSWITCH: /* prevent vty switching */
975 if ((*(int *)data) & 0x01)
976 sc->flags |= SC_SCRN_VTYLOCK;
978 sc->flags &= ~SC_SCRN_VTYLOCK;
981 case KDENABIO: /* allow io operations */
987 p->p_md.md_regs->tf_eflags |= PSL_IOPL;
990 case KDDISABIO: /* disallow io operations (default) */
991 p->p_md.md_regs->tf_eflags &= ~PSL_IOPL;
994 case KDSKBSTATE: /* set keyboard state (locks) */
995 if (*(int *)data & ~LOCK_MASK)
997 scp->status &= ~LOCK_MASK;
998 scp->status |= *(int *)data;
999 if (scp == sc->cur_scp)
1000 update_kbd_state(scp, scp->status, LOCK_MASK);
1003 case KDGKBSTATE: /* get keyboard state (locks) */
1004 if (scp == sc->cur_scp)
1005 save_kbd_state(scp);
1006 *(int *)data = scp->status & LOCK_MASK;
1009 case KDGETREPEAT: /* get keyboard repeat & delay rates */
1010 case KDSETREPEAT: /* set keyboard repeat & delay rates (new) */
1011 error = kbd_ioctl(sc->kbd, cmd, data);
1012 if (error == ENOIOCTL)
1016 case KDSETRAD: /* set keyboard repeat & delay rates (old) */
1017 if (*(int *)data & ~0x7f)
1019 error = kbd_ioctl(sc->kbd, cmd, data);
1020 if (error == ENOIOCTL)
1024 case KDSKBMODE: /* set keyboard mode */
1025 switch (*(int *)data) {
1026 case K_XLATE: /* switch to XLT ascii mode */
1027 case K_RAW: /* switch to RAW scancode mode */
1028 case K_CODE: /* switch to CODE mode */
1029 scp->kbd_mode = *(int *)data;
1030 if (scp == sc->cur_scp)
1031 kbd_ioctl(sc->kbd, cmd, data);
1038 case KDGKBMODE: /* get keyboard mode */
1039 *(int *)data = scp->kbd_mode;
1043 error = kbd_ioctl(sc->kbd, cmd, data);
1044 if (error == ENOIOCTL)
1048 case KDMKTONE: /* sound the bell */
1050 sc_bell(scp, (*(int*)data)&0xffff,
1051 (((*(int*)data)>>16)&0xffff)*hz/1000);
1053 sc_bell(scp, scp->bell_pitch, scp->bell_duration);
1056 case KIOCSOUND: /* make tone (*data) hz */
1057 if (scp == sc->cur_scp) {
1059 return sc_tone(*(int *)data);
1065 case KDGKBTYPE: /* get keyboard type */
1066 error = kbd_ioctl(sc->kbd, cmd, data);
1067 if (error == ENOIOCTL) {
1068 /* always return something? XXX */
1073 case KDSETLED: /* set keyboard LED status */
1074 if (*(int *)data & ~LED_MASK) /* FIXME: LOCK_MASK? */
1076 scp->status &= ~LED_MASK;
1077 scp->status |= *(int *)data;
1078 if (scp == sc->cur_scp)
1079 update_kbd_leds(scp, scp->status);
1082 case KDGETLED: /* get keyboard LED status */
1083 if (scp == sc->cur_scp)
1084 save_kbd_state(scp);
1085 *(int *)data = scp->status & LED_MASK;
1088 case CONS_SETKBD: /* set the new keyboard */
1093 newkbd = kbd_get_keyboard(*(int *)data);
1094 if (newkbd == NULL) {
1099 if (sc->kbd != newkbd) {
1100 i = kbd_allocate(newkbd->kb_name, newkbd->kb_unit,
1101 (void *)&sc->keyboard, sckbdevent, sc);
1102 /* i == newkbd->kb_index */
1104 if (sc->kbd != NULL) {
1105 save_kbd_state(sc->cur_scp);
1106 kbd_release(sc->kbd, (void *)&sc->keyboard);
1108 sc->kbd = kbd_get_keyboard(i); /* sc->kbd == newkbd */
1110 kbd_ioctl(sc->kbd, KDSKBMODE,
1111 (caddr_t)&sc->cur_scp->kbd_mode);
1112 update_kbd_state(sc->cur_scp, sc->cur_scp->status,
1115 error = EPERM; /* XXX */
1122 case CONS_RELKBD: /* release the current keyboard */
1125 if (sc->kbd != NULL) {
1126 save_kbd_state(sc->cur_scp);
1127 error = kbd_release(sc->kbd, (void *)&sc->keyboard);
1136 case CONS_GETTERM: /* get the current terminal emulator info */
1140 if (((term_info_t *)data)->ti_index == 0) {
1143 sw = sc_term_match_by_number(((term_info_t *)data)->ti_index);
1146 strncpy(((term_info_t *)data)->ti_name, sw->te_name,
1147 sizeof(((term_info_t *)data)->ti_name));
1148 strncpy(((term_info_t *)data)->ti_desc, sw->te_desc,
1149 sizeof(((term_info_t *)data)->ti_desc));
1150 ((term_info_t *)data)->ti_flags = 0;
1153 ((term_info_t *)data)->ti_name[0] = '\0';
1154 ((term_info_t *)data)->ti_desc[0] = '\0';
1155 ((term_info_t *)data)->ti_flags = 0;
1160 case CONS_SETTERM: /* set the current terminal emulator */
1162 error = sc_init_emulator(scp, ((term_info_t *)data)->ti_name);
1163 /* FIXME: what if scp == sc_console! XXX */
1167 case GIO_SCRNMAP: /* get output translation table */
1168 bcopy(&sc->scr_map, data, sizeof(sc->scr_map));
1171 case PIO_SCRNMAP: /* set output translation table */
1172 bcopy(data, &sc->scr_map, sizeof(sc->scr_map));
1173 for (i=0; i<sizeof(sc->scr_map); i++) {
1174 sc->scr_rmap[sc->scr_map[i]] = i;
1178 case GIO_KEYMAP: /* get keyboard translation table */
1179 case PIO_KEYMAP: /* set keyboard translation table */
1180 case GIO_DEADKEYMAP: /* get accent key translation table */
1181 case PIO_DEADKEYMAP: /* set accent key translation table */
1182 case GETFKEY: /* get function key string */
1183 case SETFKEY: /* set function key string */
1184 error = kbd_ioctl(sc->kbd, cmd, data);
1185 if (error == ENOIOCTL)
1189 #ifndef SC_NO_FONT_LOADING
1191 case PIO_FONT8x8: /* set 8x8 dot font */
1192 if (!ISFONTAVAIL(sc->adp->va_flags))
1194 bcopy(data, sc->font_8, 8*256);
1195 sc->fonts_loaded |= FONT_8;
1198 * Always use the font page #0. XXX
1199 * Don't load if the current font size is not 8x8.
1201 if (ISTEXTSC(sc->cur_scp) && (sc->cur_scp->font_size < 14))
1202 sc_load_font(sc->cur_scp, 0, 8, sc->font_8, 0, 256);
1205 case GIO_FONT8x8: /* get 8x8 dot font */
1206 if (!ISFONTAVAIL(sc->adp->va_flags))
1208 if (sc->fonts_loaded & FONT_8) {
1209 bcopy(sc->font_8, data, 8*256);
1215 case PIO_FONT8x14: /* set 8x14 dot font */
1216 if (!ISFONTAVAIL(sc->adp->va_flags))
1218 bcopy(data, sc->font_14, 14*256);
1219 sc->fonts_loaded |= FONT_14;
1222 * Always use the font page #0. XXX
1223 * Don't load if the current font size is not 8x14.
1225 if (ISTEXTSC(sc->cur_scp)
1226 && (sc->cur_scp->font_size >= 14)
1227 && (sc->cur_scp->font_size < 16))
1228 sc_load_font(sc->cur_scp, 0, 14, sc->font_14, 0, 256);
1231 case GIO_FONT8x14: /* get 8x14 dot font */
1232 if (!ISFONTAVAIL(sc->adp->va_flags))
1234 if (sc->fonts_loaded & FONT_14) {
1235 bcopy(sc->font_14, data, 14*256);
1241 case PIO_FONT8x16: /* set 8x16 dot font */
1242 if (!ISFONTAVAIL(sc->adp->va_flags))
1244 bcopy(data, sc->font_16, 16*256);
1245 sc->fonts_loaded |= FONT_16;
1248 * Always use the font page #0. XXX
1249 * Don't load if the current font size is not 8x16.
1251 if (ISTEXTSC(sc->cur_scp) && (sc->cur_scp->font_size >= 16))
1252 sc_load_font(sc->cur_scp, 0, 16, sc->font_16, 0, 256);
1255 case GIO_FONT8x16: /* get 8x16 dot font */
1256 if (!ISFONTAVAIL(sc->adp->va_flags))
1258 if (sc->fonts_loaded & FONT_16) {
1259 bcopy(sc->font_16, data, 16*256);
1265 #endif /* SC_NO_FONT_LOADING */
1271 error = (*linesw[tp->t_line].l_ioctl)(tp, cmd, data, flag, td);
1272 if (error != ENOIOCTL)
1274 error = ttioctl(tp, cmd, data, flag);
1275 if (error != ENOIOCTL)
1281 scstart(struct tty *tp)
1285 u_char buf[PCBURST];
1286 scr_stat *scp = SC_STAT(tp->t_dev);
1288 if (scp->status & SLKED ||
1289 (scp == scp->sc->cur_scp && scp->sc->blink_in_progress))
1292 if (!(tp->t_state & (TS_TIMEOUT | TS_BUSY | TS_TTSTOP))) {
1293 tp->t_state |= TS_BUSY;
1296 len = q_to_b(rbp, buf, PCBURST);
1298 sc_puts(scp, buf, len);
1301 tp->t_state &= ~TS_BUSY;
1308 sccnprobe(struct consdev *cp)
1313 cp->cn_pri = sc_get_cons_priority(&unit, &flags);
1315 /* a video card is always required */
1316 if (!scvidprobe(unit, flags, TRUE))
1317 cp->cn_pri = CN_DEAD;
1319 /* syscons will become console even when there is no keyboard */
1320 sckbdprobe(unit, flags, TRUE);
1322 if (cp->cn_pri == CN_DEAD)
1325 /* initialize required fields */
1326 cp->cn_dev = make_dev(&sc_cdevsw, SC_CONSOLECTL,
1327 UID_ROOT, GID_WHEEL, 0600, "consolectl");
1331 sccninit(struct consdev *cp)
1336 sc_get_cons_priority(&unit, &flags);
1337 scinit(unit, flags | SC_KERNEL_CONSOLE);
1338 sc_console_unit = unit;
1339 sc_console = SC_STAT(sc_get_softc(unit, SC_KERNEL_CONSOLE)->dev[0]);
1343 sccnterm(struct consdev *cp)
1345 /* we are not the kernel console any more, release everything */
1347 if (sc_console_unit < 0)
1348 return; /* shouldn't happen */
1351 sc_clear_screen(sc_console);
1352 sccnupdate(sc_console);
1354 scterm(sc_console_unit, SC_KERNEL_CONSOLE);
1355 sc_console_unit = -1;
1360 sccnputc(dev_t dev, int c)
1363 scr_stat *scp = sc_console;
1365 #ifndef SC_NO_HISTORY
1367 #endif /* !SC_NO_HISTORY */
1370 /* assert(sc_console != NULL) */
1372 #ifndef SC_NO_HISTORY
1373 if (scp == scp->sc->cur_scp && scp->status & SLKED) {
1374 scp->status &= ~SLKED;
1375 update_kbd_state(scp, scp->status, SLKED);
1376 if (scp->status & BUFFER_SAVED) {
1377 if (!sc_hist_restore(scp))
1378 sc_remove_cutmarking(scp);
1379 scp->status &= ~BUFFER_SAVED;
1380 scp->status |= CURSOR_ENABLED;
1381 sc_draw_cursor_image(scp);
1383 tp = VIRTUAL_TTY(scp->sc, scp->index);
1387 #endif /* !SC_NO_HISTORY */
1390 if (kernel_console_ts != NULL)
1391 scp->ts = kernel_console_ts;
1393 sc_puts(scp, buf, 1);
1396 s = spltty(); /* block sckbdevent and scrn_timer */
1404 return sccngetch(0);
1408 sccncheckc(dev_t dev)
1410 return sccngetch(SCGETC_NONBLOCK);
1414 sccndbctl(dev_t dev, int on)
1416 /* assert(sc_console_unit >= 0) */
1417 /* try to switch to the kernel console screen */
1418 if (on && debugger == 0) {
1420 * TRY to make sure the screen saver is stopped,
1421 * and the screen is updated before switching to
1426 && sc_console->sc->cur_scp->smode.mode == VT_AUTO
1427 && sc_console->smode.mode == VT_AUTO) {
1428 sc_console->sc->cur_scp->status |= MOUSE_HIDDEN;
1429 sc_switch_scr(sc_console->sc, sc_console->index);
1439 sccngetch(int flags)
1441 static struct fkeytab fkey;
1446 int s = spltty(); /* block sckbdevent and scrn_timer while we poll */
1449 /* assert(sc_console != NULL) */
1452 * Stop the screen saver and update the screen if necessary.
1453 * What if we have been running in the screen saver code... XXX
1455 sc_touch_scrn_saver();
1456 scp = sc_console->sc->cur_scp; /* XXX */
1459 if (fkeycp < fkey.len) {
1461 return fkey.str[fkeycp++];
1464 if (scp->sc->kbd == NULL) {
1470 * Make sure the keyboard is accessible even when the kbd device
1471 * driver is disabled.
1473 kbd_enable(scp->sc->kbd);
1475 /* we shall always use the keyboard in the XLATE mode here */
1476 cur_mode = scp->kbd_mode;
1477 scp->kbd_mode = K_XLATE;
1478 kbd_ioctl(scp->sc->kbd, KDSKBMODE, (caddr_t)&scp->kbd_mode);
1480 kbd_poll(scp->sc->kbd, TRUE);
1481 c = scgetc(scp->sc, SCGETC_CN | flags);
1482 kbd_poll(scp->sc->kbd, FALSE);
1484 scp->kbd_mode = cur_mode;
1485 kbd_ioctl(scp->sc->kbd, KDSKBMODE, (caddr_t)&scp->kbd_mode);
1486 kbd_disable(scp->sc->kbd);
1489 switch (KEYFLAGS(c)) {
1490 case 0: /* normal char */
1492 case FKEY: /* function key */
1493 p = kbd_get_fkeystr(scp->sc->kbd, KEYCHAR(c), (size_t *)&fkeycp);
1495 if ((p != NULL) && (fkey.len > 0)) {
1496 bcopy(p, fkey.str, fkey.len);
1510 sccnupdate(scr_stat *scp)
1512 /* this is a cut-down version of scrn_timer()... */
1514 if (scp->sc->font_loading_in_progress || scp->sc->videoio_in_progress)
1517 if (debugger > 0 || panicstr || shutdown_in_progress) {
1518 sc_touch_scrn_saver();
1519 } else if (scp != scp->sc->cur_scp) {
1523 if (!run_scrn_saver)
1524 scp->sc->flags &= ~SC_SCRN_IDLE;
1526 if ((saver_mode != CONS_LKM_SAVER) || !(scp->sc->flags & SC_SCRN_IDLE))
1527 if (scp->sc->flags & SC_SCRN_BLANKED)
1528 stop_scrn_saver(scp->sc, current_saver);
1529 #endif /* NSPLASH */
1531 if (scp != scp->sc->cur_scp || scp->sc->blink_in_progress
1532 || scp->sc->switch_in_progress)
1535 * FIXME: unlike scrn_timer(), we call scrn_update() from here even
1536 * when write_in_progress is non-zero. XXX
1539 if (!ISGRAPHSC(scp) && !(scp->sc->flags & SC_SCRN_BLANKED))
1540 scrn_update(scp, TRUE);
1544 scrn_timer(void *arg)
1546 static int kbd_interval = 0;
1553 again = (arg != NULL);
1555 sc = (sc_softc_t *)arg;
1556 else if (sc_console != NULL)
1557 sc = sc_console->sc;
1561 /* don't do anything when we are performing some I/O operations */
1562 if (sc->font_loading_in_progress || sc->videoio_in_progress) {
1564 callout_reset(&sc->scrn_timer_ch, hz / 10, scrn_timer, sc);
1569 if ((sc->kbd == NULL) && (sc->config & SC_AUTODETECT_KBD)) {
1570 /* try to allocate a keyboard automatically */
1571 if (++kbd_interval >= 25) {
1572 sc->keyboard = kbd_allocate("*", -1, (void *)&sc->keyboard,
1574 if (sc->keyboard >= 0) {
1575 sc->kbd = kbd_get_keyboard(sc->keyboard);
1576 kbd_ioctl(sc->kbd, KDSKBMODE,
1577 (caddr_t)&sc->cur_scp->kbd_mode);
1578 update_kbd_state(sc->cur_scp, sc->cur_scp->status,
1585 /* find the vty to update */
1588 /* should we stop the screen saver? */
1589 getmicrouptime(&tv);
1590 if (debugger > 0 || panicstr || shutdown_in_progress)
1591 sc_touch_scrn_saver();
1592 if (run_scrn_saver) {
1593 if (tv.tv_sec > sc->scrn_time_stamp + scrn_blank_time)
1594 sc->flags |= SC_SCRN_IDLE;
1596 sc->flags &= ~SC_SCRN_IDLE;
1598 sc->scrn_time_stamp = tv.tv_sec;
1599 sc->flags &= ~SC_SCRN_IDLE;
1600 if (scrn_blank_time > 0)
1601 run_scrn_saver = TRUE;
1604 if ((saver_mode != CONS_LKM_SAVER) || !(sc->flags & SC_SCRN_IDLE))
1605 if (sc->flags & SC_SCRN_BLANKED)
1606 stop_scrn_saver(sc, current_saver);
1607 #endif /* NSPLASH */
1609 /* should we just return ? */
1610 if (sc->blink_in_progress || sc->switch_in_progress
1611 || sc->write_in_progress) {
1613 callout_reset(&sc->scrn_timer_ch, hz / 10, scrn_timer, sc);
1618 /* Update the screen */
1619 scp = sc->cur_scp; /* cur_scp may have changed... */
1620 if (!ISGRAPHSC(scp) && !(sc->flags & SC_SCRN_BLANKED))
1621 scrn_update(scp, TRUE);
1624 /* should we activate the screen saver? */
1625 if ((saver_mode == CONS_LKM_SAVER) && (sc->flags & SC_SCRN_IDLE))
1626 if (!ISGRAPHSC(scp) || (sc->flags & SC_SCRN_BLANKED))
1627 (*current_saver)(sc, TRUE);
1628 #endif /* NSPLASH */
1631 callout_reset(&sc->scrn_timer_ch, hz / 25, scrn_timer, sc);
1636 and_region(int *s1, int *e1, int s2, int e2)
1638 if (*e1 < s2 || e2 < *s1)
1640 *s1 = imax(*s1, s2);
1641 *e1 = imin(*e1, e2);
1646 scrn_update(scr_stat *scp, int show_cursor)
1653 /* assert(scp == scp->sc->cur_scp) */
1655 ++scp->sc->videoio_in_progress;
1657 #ifndef SC_NO_CUTPASTE
1658 /* remove the previous mouse pointer image if necessary */
1659 if (scp->status & MOUSE_VISIBLE) {
1661 e = scp->mouse_pos + scp->xsize + 1;
1662 if ((scp->status & (MOUSE_MOVED | MOUSE_HIDDEN))
1663 || and_region(&s, &e, scp->start, scp->end)
1664 || ((scp->status & CURSOR_ENABLED) &&
1665 (scp->cursor_pos != scp->cursor_oldpos) &&
1666 (and_region(&s, &e, scp->cursor_pos, scp->cursor_pos)
1667 || and_region(&s, &e, scp->cursor_oldpos, scp->cursor_oldpos)))) {
1668 sc_remove_mouse_image(scp);
1669 if (scp->end >= scp->xsize*scp->ysize)
1670 scp->end = scp->xsize*scp->ysize - 1;
1673 #endif /* !SC_NO_CUTPASTE */
1677 if (scp->end >= scp->xsize*scp->ysize) {
1678 printf("scrn_update(): scp->end %d > size_of_screen!!\n", scp->end);
1679 scp->end = scp->xsize*scp->ysize - 1;
1681 if (scp->start < 0) {
1682 printf("scrn_update(): scp->start %d < 0\n", scp->start);
1687 /* update screen image */
1688 if (scp->start <= scp->end) {
1689 if (scp->mouse_cut_end >= 0) {
1690 /* there is a marked region for cut & paste */
1691 if (scp->mouse_cut_start <= scp->mouse_cut_end) {
1692 start = scp->mouse_cut_start;
1693 end = scp->mouse_cut_end;
1695 start = scp->mouse_cut_end;
1696 end = scp->mouse_cut_start - 1;
1700 /* does the cut-mark region overlap with the update region? */
1701 if (and_region(&s, &e, scp->start, scp->end)) {
1702 (*scp->rndr->draw)(scp, s, e - s + 1, TRUE);
1705 if (and_region(&s, &e, scp->start, scp->end))
1706 (*scp->rndr->draw)(scp, s, e - s + 1, FALSE);
1708 e = scp->xsize*scp->ysize - 1;
1709 if (and_region(&s, &e, scp->start, scp->end))
1710 (*scp->rndr->draw)(scp, s, e - s + 1, FALSE);
1712 (*scp->rndr->draw)(scp, scp->start,
1713 scp->end - scp->start + 1, FALSE);
1716 (*scp->rndr->draw)(scp, scp->start,
1717 scp->end - scp->start + 1, FALSE);
1721 /* we are not to show the cursor and the mouse pointer... */
1724 scp->start = scp->xsize*scp->ysize - 1;
1725 --scp->sc->videoio_in_progress;
1729 /* update cursor image */
1730 if (scp->status & CURSOR_ENABLED) {
1733 /* did cursor move since last time ? */
1734 if (scp->cursor_pos != scp->cursor_oldpos) {
1735 /* do we need to remove old cursor image ? */
1736 if (!and_region(&s, &e, scp->cursor_oldpos, scp->cursor_oldpos))
1737 sc_remove_cursor_image(scp);
1738 sc_draw_cursor_image(scp);
1740 if (and_region(&s, &e, scp->cursor_pos, scp->cursor_pos))
1741 /* cursor didn't move, but has been overwritten */
1742 sc_draw_cursor_image(scp);
1743 else if (scp->sc->flags & SC_BLINK_CURSOR)
1744 /* if it's a blinking cursor, update it */
1745 (*scp->rndr->blink_cursor)(scp, scp->cursor_pos,
1746 sc_inside_cutmark(scp,
1751 #ifndef SC_NO_CUTPASTE
1752 /* update "pseudo" mouse pointer image */
1753 if (scp->sc->flags & SC_MOUSE_ENABLED) {
1754 if (!(scp->status & (MOUSE_VISIBLE | MOUSE_HIDDEN))) {
1755 scp->status &= ~MOUSE_MOVED;
1756 sc_draw_mouse_image(scp);
1759 #endif /* SC_NO_CUTPASTE */
1762 scp->start = scp->xsize*scp->ysize - 1;
1764 --scp->sc->videoio_in_progress;
1769 scsplash_callback(int event, void *arg)
1774 sc = (sc_softc_t *)arg;
1778 if (add_scrn_saver(scsplash_saver) == 0) {
1779 sc->flags &= ~SC_SAVER_FAILED;
1780 run_scrn_saver = TRUE;
1781 if (cold && !(boothowto & (RB_VERBOSE | RB_CONFIG))) {
1782 scsplash_stick(TRUE);
1783 (*current_saver)(sc, TRUE);
1789 if (current_saver == scsplash_saver) {
1790 scsplash_stick(FALSE);
1791 error = remove_scrn_saver(scsplash_saver);
1803 scsplash_saver(sc_softc_t *sc, int show)
1805 static int busy = FALSE;
1814 if (!(sc->flags & SC_SAVER_FAILED)) {
1815 if (!(sc->flags & SC_SCRN_BLANKED))
1816 set_scrn_saver_mode(scp, -1, NULL, 0);
1817 switch (splash(sc->adp, TRUE)) {
1818 case 0: /* succeeded */
1820 case EAGAIN: /* try later */
1821 restore_scrn_saver_mode(scp, FALSE);
1822 sc_touch_scrn_saver(); /* XXX */
1825 sc->flags |= SC_SAVER_FAILED;
1826 scsplash_stick(FALSE);
1827 restore_scrn_saver_mode(scp, TRUE);
1828 printf("scsplash_saver(): failed to put up the image\n");
1832 } else if (!sticky_splash) {
1833 if ((sc->flags & SC_SCRN_BLANKED) && (splash(sc->adp, FALSE) == 0))
1834 restore_scrn_saver_mode(scp, TRUE);
1840 add_scrn_saver(void (*this_saver)(sc_softc_t *, int))
1845 if (current_saver != none_saver) {
1846 error = remove_scrn_saver(current_saver);
1851 if (current_saver != none_saver)
1854 run_scrn_saver = FALSE;
1855 saver_mode = CONS_LKM_SAVER;
1856 current_saver = this_saver;
1861 remove_scrn_saver(void (*this_saver)(sc_softc_t *, int))
1863 if (current_saver != this_saver)
1868 * In order to prevent `current_saver' from being called by
1869 * the timeout routine `scrn_timer()' while we manipulate
1870 * the saver list, we shall set `current_saver' to `none_saver'
1871 * before stopping the current saver, rather than blocking by `splXX()'.
1873 current_saver = none_saver;
1875 stop_scrn_saver(this_saver);
1878 /* unblank all blanked screens */
1879 wait_scrn_saver_stop(NULL);
1883 current_saver = none_saver;
1888 set_scrn_saver_mode(scr_stat *scp, int mode, u_char *pal, int border)
1892 /* assert(scp == scp->sc->cur_scp) */
1894 if (!ISGRAPHSC(scp))
1895 sc_remove_cursor_image(scp);
1896 scp->splash_save_mode = scp->mode;
1897 scp->splash_save_status = scp->status & (GRAPHICS_MODE | PIXEL_MODE);
1898 scp->status &= ~(GRAPHICS_MODE | PIXEL_MODE);
1899 scp->status |= (UNKNOWN_MODE | SAVER_RUNNING);
1900 scp->sc->flags |= SC_SCRN_BLANKED;
1906 if (set_mode(scp) == 0) {
1907 if (scp->sc->adp->va_info.vi_flags & V_INFO_GRAPHICS)
1908 scp->status |= GRAPHICS_MODE;
1909 #ifndef SC_NO_PALETTE_LOADING
1911 load_palette(scp->sc->adp, pal);
1913 sc_set_border(scp, border);
1917 scp->mode = scp->splash_save_mode;
1918 scp->status &= ~(UNKNOWN_MODE | SAVER_RUNNING);
1919 scp->status |= scp->splash_save_status;
1926 restore_scrn_saver_mode(scr_stat *scp, int changemode)
1932 /* assert(scp == scp->sc->cur_scp) */
1935 status = scp->status;
1936 scp->mode = scp->splash_save_mode;
1937 scp->status &= ~(UNKNOWN_MODE | SAVER_RUNNING);
1938 scp->status |= scp->splash_save_status;
1939 scp->sc->flags &= ~SC_SCRN_BLANKED;
1941 if (!ISGRAPHSC(scp))
1942 sc_draw_cursor_image(scp);
1947 if (set_mode(scp) == 0) {
1948 #ifndef SC_NO_PALETTE_LOADING
1949 load_palette(scp->sc->adp, scp->sc->palette);
1956 scp->status = status;
1963 stop_scrn_saver(sc_softc_t *sc, void (*saver)(sc_softc_t *, int))
1965 (*saver)(sc, FALSE);
1966 run_scrn_saver = FALSE;
1967 /* the screen saver may have chosen not to stop after all... */
1968 if (sc->flags & SC_SCRN_BLANKED)
1971 mark_all(sc->cur_scp);
1972 if (sc->delayed_next_scr)
1973 sc_switch_scr(sc, sc->delayed_next_scr - 1);
1974 wakeup((caddr_t)&scrn_blanked);
1978 wait_scrn_saver_stop(sc_softc_t *sc)
1982 while (scrn_blanked > 0) {
1983 run_scrn_saver = FALSE;
1984 if (sc && !(sc->flags & SC_SCRN_BLANKED)) {
1988 error = tsleep((caddr_t)&scrn_blanked, PCATCH, "scrsav", 0);
1989 if ((error != 0) && (error != ERESTART))
1992 run_scrn_saver = FALSE;
1995 #endif /* NSPLASH */
1998 sc_touch_scrn_saver(void)
2000 scsplash_stick(FALSE);
2001 run_scrn_saver = FALSE;
2005 sc_switch_scr(sc_softc_t *sc, u_int next_scr)
2011 DPRINTF(5, ("sc0: sc_switch_scr() %d ", next_scr + 1));
2013 /* prevent switch if previously requested */
2014 if (sc->flags & SC_SCRN_VTYLOCK) {
2015 sc_bell(sc->cur_scp, sc->cur_scp->bell_pitch,
2016 sc->cur_scp->bell_duration);
2020 /* delay switch if the screen is blanked or being updated */
2021 if ((sc->flags & SC_SCRN_BLANKED) || sc->write_in_progress
2022 || sc->blink_in_progress || sc->videoio_in_progress) {
2023 sc->delayed_next_scr = next_scr + 1;
2024 sc_touch_scrn_saver();
2025 DPRINTF(5, ("switch delayed\n"));
2030 cur_scp = sc->cur_scp;
2032 /* we are in the middle of the vty switching process... */
2033 if (sc->switch_in_progress
2034 && (cur_scp->smode.mode == VT_PROCESS)
2036 if (cur_scp->proc != pfind(cur_scp->pid)) {
2038 * The controlling process has died!!. Do some clean up.
2039 * NOTE:`cur_scp->proc' and `cur_scp->smode.mode'
2040 * are not reset here yet; they will be cleared later.
2042 DPRINTF(5, ("cur_scp controlling process %d died, ",
2044 if (cur_scp->status & SWITCH_WAIT_REL) {
2046 * Force the previous switch to finish, but return now
2049 DPRINTF(5, ("reset WAIT_REL, "));
2050 finish_vt_rel(cur_scp, TRUE, &s);
2052 DPRINTF(5, ("finishing previous switch\n"));
2054 } else if (cur_scp->status & SWITCH_WAIT_ACQ) {
2055 /* let's assume screen switch has been completed. */
2056 DPRINTF(5, ("reset WAIT_ACQ, "));
2057 finish_vt_acq(cur_scp);
2060 * We are in between screen release and acquisition, and
2061 * reached here via scgetc() or scrn_timer() which has
2062 * interrupted exchange_scr(). Don't do anything stupid.
2064 DPRINTF(5, ("waiting nothing, "));
2068 * The controlling process is alive, but not responding...
2069 * It is either buggy or it may be just taking time.
2070 * The following code is a gross kludge to cope with this
2071 * problem for which there is no clean solution. XXX
2073 if (cur_scp->status & SWITCH_WAIT_REL) {
2074 switch (sc->switch_in_progress++) {
2078 DPRINTF(5, ("sending relsig again, "));
2079 signal_vt_rel(cur_scp);
2086 * Act as if the controlling program returned
2089 DPRINTF(5, ("force reset WAIT_REL, "));
2090 finish_vt_rel(cur_scp, FALSE, &s);
2092 DPRINTF(5, ("act as if VT_FALSE was seen\n"));
2095 } else if (cur_scp->status & SWITCH_WAIT_ACQ) {
2096 switch (sc->switch_in_progress++) {
2100 DPRINTF(5, ("sending acqsig again, "));
2101 signal_vt_acq(cur_scp);
2107 /* clear the flag and finish the previous switch */
2108 DPRINTF(5, ("force reset WAIT_ACQ, "));
2109 finish_vt_acq(cur_scp);
2117 * Return error if an invalid argument is given, or vty switch
2118 * is still in progress.
2120 if ((next_scr < sc->first_vty) || (next_scr >= sc->first_vty + sc->vtys)
2121 || sc->switch_in_progress) {
2123 sc_bell(cur_scp, bios_value.bell_pitch, BELL_DURATION);
2124 DPRINTF(5, ("error 1\n"));
2129 * Don't allow switching away from the graphics mode vty
2130 * if the switch mode is VT_AUTO, unless the next vty is the same
2131 * as the current or the current vty has been closed (but showing).
2133 tp = VIRTUAL_TTY(sc, cur_scp->index);
2134 if ((cur_scp->index != next_scr)
2136 && (cur_scp->smode.mode == VT_AUTO)
2137 && ISGRAPHSC(cur_scp)) {
2139 sc_bell(cur_scp, bios_value.bell_pitch, BELL_DURATION);
2140 DPRINTF(5, ("error, graphics mode\n"));
2145 * Is the wanted vty open? Don't allow switching to a closed vty.
2146 * If we are in DDB, don't switch to a vty in the VT_PROCESS mode.
2147 * Note that we always allow the user to switch to the kernel
2148 * console even if it is closed.
2150 if ((sc_console == NULL) || (next_scr != sc_console->index)) {
2151 tp = VIRTUAL_TTY(sc, next_scr);
2152 if (!ISTTYOPEN(tp)) {
2154 sc_bell(cur_scp, bios_value.bell_pitch, BELL_DURATION);
2155 DPRINTF(5, ("error 2, requested vty isn't open!\n"));
2158 if ((debugger > 0) && (SC_STAT(tp->t_dev)->smode.mode == VT_PROCESS)) {
2160 DPRINTF(5, ("error 3, requested vty is in the VT_PROCESS mode\n"));
2165 /* this is the start of vty switching process... */
2166 ++sc->switch_in_progress;
2167 sc->delayed_next_scr = 0;
2168 sc->old_scp = cur_scp;
2169 sc->new_scp = SC_STAT(SC_DEV(sc, next_scr));
2170 if (sc->new_scp == sc->old_scp) {
2171 sc->switch_in_progress = 0;
2172 wakeup((caddr_t)&sc->new_scp->smode);
2174 DPRINTF(5, ("switch done (new == old)\n"));
2178 /* has controlling process died? */
2179 vt_proc_alive(sc->old_scp);
2180 vt_proc_alive(sc->new_scp);
2182 /* wait for the controlling process to release the screen, if necessary */
2183 if (signal_vt_rel(sc->old_scp)) {
2188 /* go set up the new vty screen */
2193 /* wake up processes waiting for this vty */
2194 wakeup((caddr_t)&sc->cur_scp->smode);
2196 /* wait for the controlling process to acknowledge, if necessary */
2197 if (signal_vt_acq(sc->cur_scp)) {
2202 sc->switch_in_progress = 0;
2203 if (sc->unit == sc_console_unit)
2204 cons_unavail = FALSE;
2206 DPRINTF(5, ("switch done\n"));
2212 do_switch_scr(sc_softc_t *sc, int s)
2214 vt_proc_alive(sc->new_scp);
2219 /* sc->cur_scp == sc->new_scp */
2220 wakeup((caddr_t)&sc->cur_scp->smode);
2222 /* wait for the controlling process to acknowledge, if necessary */
2223 if (!signal_vt_acq(sc->cur_scp)) {
2224 sc->switch_in_progress = 0;
2225 if (sc->unit == sc_console_unit)
2226 cons_unavail = FALSE;
2233 vt_proc_alive(scr_stat *scp)
2236 if (scp->proc == pfind(scp->pid))
2239 scp->smode.mode = VT_AUTO;
2240 DPRINTF(5, ("vt controlling process %d died\n", scp->pid));
2246 signal_vt_rel(scr_stat *scp)
2248 if (scp->smode.mode != VT_PROCESS)
2250 scp->status |= SWITCH_WAIT_REL;
2251 psignal(scp->proc, scp->smode.relsig);
2252 DPRINTF(5, ("sending relsig to %d\n", scp->pid));
2257 signal_vt_acq(scr_stat *scp)
2259 if (scp->smode.mode != VT_PROCESS)
2261 if (scp->sc->unit == sc_console_unit)
2262 cons_unavail = TRUE;
2263 scp->status |= SWITCH_WAIT_ACQ;
2264 psignal(scp->proc, scp->smode.acqsig);
2265 DPRINTF(5, ("sending acqsig to %d\n", scp->pid));
2270 finish_vt_rel(scr_stat *scp, int release, int *s)
2272 if (scp == scp->sc->old_scp && scp->status & SWITCH_WAIT_REL) {
2273 scp->status &= ~SWITCH_WAIT_REL;
2275 *s = do_switch_scr(scp->sc, *s);
2277 scp->sc->switch_in_progress = 0;
2284 finish_vt_acq(scr_stat *scp)
2286 if (scp == scp->sc->new_scp && scp->status & SWITCH_WAIT_ACQ) {
2287 scp->status &= ~SWITCH_WAIT_ACQ;
2288 scp->sc->switch_in_progress = 0;
2295 exchange_scr(sc_softc_t *sc)
2299 /* save the current state of video and keyboard */
2300 sc_move_cursor(sc->old_scp, sc->old_scp->xpos, sc->old_scp->ypos);
2301 if (!ISGRAPHSC(sc->old_scp))
2302 sc_remove_cursor_image(sc->old_scp);
2303 if (sc->old_scp->kbd_mode == K_XLATE)
2304 save_kbd_state(sc->old_scp);
2306 /* set up the video for the new screen */
2307 scp = sc->cur_scp = sc->new_scp;
2308 if (sc->old_scp->mode != scp->mode || ISUNKNOWNSC(sc->old_scp))
2311 sc_vtb_init(&scp->scr, VTB_FRAMEBUFFER, scp->xsize, scp->ysize,
2312 (void *)sc->adp->va_window, FALSE);
2313 scp->status |= MOUSE_HIDDEN;
2314 sc_move_cursor(scp, scp->xpos, scp->ypos);
2315 if (!ISGRAPHSC(scp))
2316 sc_set_cursor_image(scp);
2317 #ifndef SC_NO_PALETTE_LOADING
2318 if (ISGRAPHSC(sc->old_scp))
2319 load_palette(sc->adp, sc->palette);
2321 sc_set_border(scp, scp->border);
2323 /* set up the keyboard for the new screen */
2324 if (sc->old_scp->kbd_mode != scp->kbd_mode)
2325 kbd_ioctl(sc->kbd, KDSKBMODE, (caddr_t)&scp->kbd_mode);
2326 update_kbd_state(scp, scp->status, LOCK_MASK);
2332 sc_puts(scr_stat *scp, u_char *buf, int len)
2335 /* make screensaver happy */
2336 if (!sticky_splash && scp == scp->sc->cur_scp)
2337 run_scrn_saver = FALSE;
2341 (*scp->tsw->te_puts)(scp, buf, len);
2343 if (scp->sc->delayed_next_scr)
2344 sc_switch_scr(scp->sc, scp->sc->delayed_next_scr - 1);
2348 sc_draw_cursor_image(scr_stat *scp)
2350 /* assert(scp == scp->sc->cur_scp); */
2351 ++scp->sc->videoio_in_progress;
2352 (*scp->rndr->draw_cursor)(scp, scp->cursor_pos,
2353 scp->sc->flags & SC_BLINK_CURSOR, TRUE,
2354 sc_inside_cutmark(scp, scp->cursor_pos));
2355 scp->cursor_oldpos = scp->cursor_pos;
2356 --scp->sc->videoio_in_progress;
2360 sc_remove_cursor_image(scr_stat *scp)
2362 /* assert(scp == scp->sc->cur_scp); */
2363 ++scp->sc->videoio_in_progress;
2364 (*scp->rndr->draw_cursor)(scp, scp->cursor_oldpos,
2365 scp->sc->flags & SC_BLINK_CURSOR, FALSE,
2366 sc_inside_cutmark(scp, scp->cursor_oldpos));
2367 --scp->sc->videoio_in_progress;
2371 update_cursor_image(scr_stat *scp)
2375 if (scp->sc->flags & SC_CHAR_CURSOR) {
2376 scp->cursor_base = imax(0, scp->sc->cursor_base);
2377 scp->cursor_height = imin(scp->sc->cursor_height, scp->font_size);
2379 scp->cursor_base = 0;
2380 scp->cursor_height = scp->font_size;
2382 blink = scp->sc->flags & SC_BLINK_CURSOR;
2384 /* assert(scp == scp->sc->cur_scp); */
2385 ++scp->sc->videoio_in_progress;
2386 (*scp->rndr->draw_cursor)(scp, scp->cursor_oldpos, blink, FALSE,
2387 sc_inside_cutmark(scp, scp->cursor_pos));
2388 (*scp->rndr->set_cursor)(scp, scp->cursor_base, scp->cursor_height, blink);
2389 (*scp->rndr->draw_cursor)(scp, scp->cursor_pos, blink, TRUE,
2390 sc_inside_cutmark(scp, scp->cursor_pos));
2391 --scp->sc->videoio_in_progress;
2395 sc_set_cursor_image(scr_stat *scp)
2397 if (scp->sc->flags & SC_CHAR_CURSOR) {
2398 scp->cursor_base = imax(0, scp->sc->cursor_base);
2399 scp->cursor_height = imin(scp->sc->cursor_height, scp->font_size);
2401 scp->cursor_base = 0;
2402 scp->cursor_height = scp->font_size;
2405 /* assert(scp == scp->sc->cur_scp); */
2406 ++scp->sc->videoio_in_progress;
2407 (*scp->rndr->set_cursor)(scp, scp->cursor_base, scp->cursor_height,
2408 scp->sc->flags & SC_BLINK_CURSOR);
2409 --scp->sc->videoio_in_progress;
2413 scinit(int unit, int flags)
2416 * When syscons is being initialized as the kernel console, malloc()
2417 * is not yet functional, because various kernel structures has not been
2418 * fully initialized yet. Therefore, we need to declare the following
2419 * static buffers for the console. This is less than ideal,
2420 * but is necessry evil for the time being. XXX
2422 static scr_stat main_console;
2423 static dev_t main_devs[MAXCONS];
2424 static struct tty main_tty;
2425 static u_short sc_buffer[ROW*COL]; /* XXX */
2426 #ifndef SC_NO_FONT_LOADING
2427 static u_char font_8[256*8];
2428 static u_char font_14[256*14];
2429 static u_char font_16[256*16];
2434 video_adapter_t *adp;
2439 /* one time initialization */
2440 if (init_done == COLD)
2441 sc_get_bios_values(&bios_value);
2445 * Allocate resources. Even if we are being called for the second
2446 * time, we must allocate them again, because they might have
2449 sc = sc_get_softc(unit, flags & SC_KERNEL_CONSOLE);
2451 if (sc->adapter >= 0) {
2452 vid_release(sc->adp, (void *)&sc->adapter);
2456 if (sc->keyboard >= 0) {
2457 DPRINTF(5, ("sc%d: releasing kbd%d\n", unit, sc->keyboard));
2458 i = kbd_release(sc->kbd, (void *)&sc->keyboard);
2459 DPRINTF(5, ("sc%d: kbd_release returned %d\n", unit, i));
2460 if (sc->kbd != NULL) {
2461 DPRINTF(5, ("sc%d: kbd != NULL!, index:%d, unit:%d, flags:0x%x\n",
2462 unit, sc->kbd->kb_index, sc->kbd->kb_unit, sc->kbd->kb_flags));
2466 sc->adapter = vid_allocate("*", unit, (void *)&sc->adapter);
2467 sc->adp = vid_get_adapter(sc->adapter);
2468 /* assert((sc->adapter >= 0) && (sc->adp != NULL)) */
2469 sc->keyboard = kbd_allocate("*", unit, (void *)&sc->keyboard,
2471 DPRINTF(1, ("sc%d: keyboard %d\n", unit, sc->keyboard));
2472 sc->kbd = kbd_get_keyboard(sc->keyboard);
2473 if (sc->kbd != NULL) {
2474 DPRINTF(1, ("sc%d: kbd index:%d, unit:%d, flags:0x%x\n",
2475 unit, sc->kbd->kb_index, sc->kbd->kb_unit, sc->kbd->kb_flags));
2478 if (!(sc->flags & SC_INIT_DONE) || (adp != sc->adp)) {
2480 sc->initial_mode = sc->adp->va_initial_mode;
2482 #ifndef SC_NO_FONT_LOADING
2483 if (flags & SC_KERNEL_CONSOLE) {
2484 sc->font_8 = font_8;
2485 sc->font_14 = font_14;
2486 sc->font_16 = font_16;
2487 } else if (sc->font_8 == NULL) {
2488 /* assert(sc_malloc) */
2489 sc->font_8 = malloc(sizeof(font_8), M_DEVBUF, M_WAITOK);
2490 sc->font_14 = malloc(sizeof(font_14), M_DEVBUF, M_WAITOK);
2491 sc->font_16 = malloc(sizeof(font_16), M_DEVBUF, M_WAITOK);
2495 /* extract the hardware cursor location and hide the cursor for now */
2496 (*vidsw[sc->adapter]->read_hw_cursor)(sc->adp, &col, &row);
2497 (*vidsw[sc->adapter]->set_hw_cursor)(sc->adp, -1, -1);
2499 /* set up the first console */
2500 sc->first_vty = unit*MAXCONS;
2501 sc->vtys = MAXCONS; /* XXX: should be configurable */
2502 if (flags & SC_KERNEL_CONSOLE) {
2503 sc->dev = main_devs;
2504 sc->dev[0] = make_dev(&sc_cdevsw, unit*MAXCONS, UID_ROOT,
2505 GID_WHEEL, 0600, "ttyv%r", unit*MAXCONS);
2506 sc->dev[0]->si_tty = &main_tty;
2507 ttyregister(&main_tty);
2508 scp = &main_console;
2509 init_scp(sc, sc->first_vty, scp);
2510 sc_vtb_init(&scp->vtb, VTB_MEMORY, scp->xsize, scp->ysize,
2511 (void *)sc_buffer, FALSE);
2512 if (sc_init_emulator(scp, SC_DFLT_TERM))
2513 sc_init_emulator(scp, "*");
2514 (*scp->tsw->te_default_attr)(scp,
2515 kernel_default.std_color,
2516 kernel_default.rev_color);
2518 /* assert(sc_malloc) */
2519 sc->dev = malloc(sizeof(dev_t)*sc->vtys, M_DEVBUF, M_WAITOK);
2520 bzero(sc->dev, sizeof(dev_t)*sc->vtys);
2521 sc->dev[0] = make_dev(&sc_cdevsw, unit*MAXCONS, UID_ROOT,
2522 GID_WHEEL, 0600, "ttyv%r", unit*MAXCONS);
2523 sc->dev[0]->si_tty = ttymalloc(sc->dev[0]->si_tty);
2524 scp = alloc_scp(sc, sc->first_vty);
2526 sc->dev[0]->si_drv1 = scp;
2529 /* copy screen to temporary buffer */
2530 sc_vtb_init(&scp->scr, VTB_FRAMEBUFFER, scp->xsize, scp->ysize,
2531 (void *)scp->sc->adp->va_window, FALSE);
2533 sc_vtb_copy(&scp->scr, 0, &scp->vtb, 0, scp->xsize*scp->ysize);
2535 /* move cursors to the initial positions */
2536 if (col >= scp->xsize)
2538 if (row >= scp->ysize)
2539 row = scp->ysize - 1;
2542 scp->cursor_pos = scp->cursor_oldpos = row*scp->xsize + col;
2543 if (bios_value.cursor_end < scp->font_size)
2544 sc->cursor_base = scp->font_size - bios_value.cursor_end - 1;
2546 sc->cursor_base = 0;
2547 i = bios_value.cursor_end - bios_value.cursor_start + 1;
2548 sc->cursor_height = imin(i, scp->font_size);
2549 #ifndef SC_NO_SYSMOUSE
2550 sc_mouse_move(scp, scp->xpixel/2, scp->ypixel/2);
2552 if (!ISGRAPHSC(scp)) {
2553 sc_set_cursor_image(scp);
2554 sc_draw_cursor_image(scp);
2557 /* save font and palette */
2558 #ifndef SC_NO_FONT_LOADING
2559 sc->fonts_loaded = 0;
2560 if (ISFONTAVAIL(sc->adp->va_flags)) {
2562 bcopy(dflt_font_8, sc->font_8, sizeof(dflt_font_8));
2563 bcopy(dflt_font_14, sc->font_14, sizeof(dflt_font_14));
2564 bcopy(dflt_font_16, sc->font_16, sizeof(dflt_font_16));
2565 sc->fonts_loaded = FONT_16 | FONT_14 | FONT_8;
2566 if (scp->font_size < 14) {
2567 sc_load_font(scp, 0, 8, sc->font_8, 0, 256);
2568 } else if (scp->font_size >= 16) {
2569 sc_load_font(scp, 0, 16, sc->font_16, 0, 256);
2571 sc_load_font(scp, 0, 14, sc->font_14, 0, 256);
2573 #else /* !SC_DFLT_FONT */
2574 if (scp->font_size < 14) {
2575 sc_save_font(scp, 0, 8, sc->font_8, 0, 256);
2576 sc->fonts_loaded = FONT_8;
2577 } else if (scp->font_size >= 16) {
2578 sc_save_font(scp, 0, 16, sc->font_16, 0, 256);
2579 sc->fonts_loaded = FONT_16;
2581 sc_save_font(scp, 0, 14, sc->font_14, 0, 256);
2582 sc->fonts_loaded = FONT_14;
2584 #endif /* SC_DFLT_FONT */
2585 /* FONT KLUDGE: always use the font page #0. XXX */
2586 sc_show_font(scp, 0);
2588 #endif /* !SC_NO_FONT_LOADING */
2590 #ifndef SC_NO_PALETTE_LOADING
2591 save_palette(sc->adp, sc->palette);
2595 if (!(sc->flags & SC_SPLASH_SCRN) && (flags & SC_KERNEL_CONSOLE)) {
2596 /* we are ready to put up the splash image! */
2597 splash_init(sc->adp, scsplash_callback, sc);
2598 sc->flags |= SC_SPLASH_SCRN;
2600 #endif /* NSPLASH */
2603 /* the rest is not necessary, if we have done it once */
2604 if (sc->flags & SC_INIT_DONE)
2607 /* initialize mapscrn arrays to a one to one map */
2608 for (i = 0; i < sizeof(sc->scr_map); i++)
2609 sc->scr_map[i] = sc->scr_rmap[i] = i;
2611 sc->flags |= SC_INIT_DONE;
2615 scterm(int unit, int flags)
2620 sc = sc_get_softc(unit, flags & SC_KERNEL_CONSOLE);
2622 return; /* shouldn't happen */
2625 /* this console is no longer available for the splash screen */
2626 if (sc->flags & SC_SPLASH_SCRN) {
2627 splash_term(sc->adp);
2628 sc->flags &= ~SC_SPLASH_SCRN;
2630 #endif /* NSPLASH */
2633 /* move the hardware cursor to the upper-left corner */
2634 (*vidsw[sc->adapter]->set_hw_cursor)(sc->adp, 0, 0);
2637 /* release the keyboard and the video card */
2638 if (sc->keyboard >= 0)
2639 kbd_release(sc->kbd, &sc->keyboard);
2640 if (sc->adapter >= 0)
2641 vid_release(sc->adp, &sc->adapter);
2643 /* stop the terminal emulator, if any */
2644 scp = SC_STAT(sc->dev[0]);
2646 (*scp->tsw->te_term)(scp, &scp->ts);
2647 if (scp->ts != NULL)
2648 free(scp->ts, M_DEVBUF);
2650 /* clear the structure */
2651 if (!(flags & SC_KERNEL_CONSOLE)) {
2652 /* XXX: We need delete_dev() for this */
2653 free(sc->dev, M_DEVBUF);
2655 /* XXX: We need a ttyunregister for this */
2656 free(sc->tty, M_DEVBUF);
2658 #ifndef SC_NO_FONT_LOADING
2659 free(sc->font_8, M_DEVBUF);
2660 free(sc->font_14, M_DEVBUF);
2661 free(sc->font_16, M_DEVBUF);
2663 /* XXX vtb, history */
2665 bzero(sc, sizeof(*sc));
2671 scshutdown(void *arg, int howto)
2673 /* assert(sc_console != NULL) */
2675 sc_touch_scrn_saver();
2676 if (!cold && sc_console
2677 && sc_console->sc->cur_scp->smode.mode == VT_AUTO
2678 && sc_console->smode.mode == VT_AUTO)
2679 sc_switch_scr(sc_console->sc, sc_console->index);
2680 shutdown_in_progress = TRUE;
2684 sc_clean_up(scr_stat *scp)
2688 #endif /* NSPLASH */
2690 if (scp->sc->flags & SC_SCRN_BLANKED) {
2691 sc_touch_scrn_saver();
2693 if ((error = wait_scrn_saver_stop(scp->sc)))
2695 #endif /* NSPLASH */
2697 scp->status |= MOUSE_HIDDEN;
2698 sc_remove_mouse_image(scp);
2699 sc_remove_cutmarking(scp);
2704 sc_alloc_scr_buffer(scr_stat *scp, int wait, int discard)
2710 sc_vtb_init(&new, VTB_MEMORY, scp->xsize, scp->ysize, NULL, wait);
2711 if (!discard && (old.vtb_flags & VTB_VALID)) {
2712 /* retain the current cursor position and buffer contants */
2713 scp->cursor_oldpos = scp->cursor_pos;
2715 * This works only if the old buffer has the same size as or larger
2716 * than the new one. XXX
2718 sc_vtb_copy(&old, 0, &new, 0, scp->xsize*scp->ysize);
2722 sc_vtb_destroy(&old);
2725 #ifndef SC_NO_SYSMOUSE
2726 /* move the mouse cursor at the center of the screen */
2727 sc_mouse_move(scp, scp->xpixel / 2, scp->ypixel / 2);
2732 *alloc_scp(sc_softc_t *sc, int vty)
2736 /* assert(sc_malloc) */
2738 scp = (scr_stat *)malloc(sizeof(scr_stat), M_DEVBUF, M_WAITOK);
2739 init_scp(sc, vty, scp);
2741 sc_alloc_scr_buffer(scp, TRUE, TRUE);
2742 if (sc_init_emulator(scp, SC_DFLT_TERM))
2743 sc_init_emulator(scp, "*");
2745 #ifndef SC_NO_CUTPASTE
2746 sc_alloc_cut_buffer(scp, TRUE);
2749 #ifndef SC_NO_HISTORY
2750 sc_alloc_history_buffer(scp, 0, 0, TRUE);
2757 init_scp(sc_softc_t *sc, int vty, scr_stat *scp)
2761 bzero(scp, sizeof(*scp));
2766 scp->mode = sc->initial_mode;
2767 callout_init(&scp->blink_screen_ch);
2768 (*vidsw[sc->adapter]->get_info)(sc->adp, scp->mode, &info);
2769 if (info.vi_flags & V_INFO_GRAPHICS) {
2770 scp->status |= GRAPHICS_MODE;
2771 scp->xpixel = info.vi_width;
2772 scp->ypixel = info.vi_height;
2773 scp->xsize = info.vi_width/8;
2774 scp->ysize = info.vi_height/info.vi_cheight;
2778 scp->xsize = info.vi_width;
2779 scp->ysize = info.vi_height;
2780 scp->xpixel = scp->xsize*8;
2781 scp->ypixel = scp->ysize*info.vi_cheight;
2782 if (info.vi_cheight < 14) {
2784 #ifndef SC_NO_FONT_LOADING
2785 scp->font = sc->font_8;
2789 } else if (info.vi_cheight >= 16) {
2790 scp->font_size = 16;
2791 #ifndef SC_NO_FONT_LOADING
2792 scp->font = sc->font_16;
2797 scp->font_size = 14;
2798 #ifndef SC_NO_FONT_LOADING
2799 scp->font = sc->font_14;
2805 sc_vtb_init(&scp->vtb, VTB_MEMORY, 0, 0, NULL, FALSE);
2806 sc_vtb_init(&scp->scr, VTB_FRAMEBUFFER, 0, 0, NULL, FALSE);
2807 scp->xoff = scp->yoff = 0;
2808 scp->xpos = scp->ypos = 0;
2809 scp->start = scp->xsize * scp->ysize - 1;
2814 scp->border = BG_BLACK;
2815 scp->cursor_base = sc->cursor_base;
2816 scp->cursor_height = imin(sc->cursor_height, scp->font_size);
2817 scp->mouse_cut_start = scp->xsize*scp->ysize;
2818 scp->mouse_cut_end = -1;
2819 scp->mouse_signal = 0;
2821 scp->mouse_proc = NULL;
2822 scp->kbd_mode = K_XLATE;
2823 scp->bell_pitch = bios_value.bell_pitch;
2824 scp->bell_duration = BELL_DURATION;
2825 scp->status |= (bios_value.shift_state & NLKED);
2826 scp->status |= CURSOR_ENABLED | MOUSE_HIDDEN;
2829 scp->smode.mode = VT_AUTO;
2830 scp->history = NULL;
2831 scp->history_pos = 0;
2832 scp->history_size = 0;
2836 sc_init_emulator(scr_stat *scp, char *name)
2843 if (name == NULL) /* if no name is given, use the current emulator */
2845 else /* ...otherwise find the named emulator */
2846 sw = sc_term_match(name);
2851 if (strcmp(sw->te_renderer, "*") != 0) {
2852 rndr = sc_render_match(scp, sw->te_renderer,
2853 scp->status & (GRAPHICS_MODE | PIXEL_MODE));
2856 rndr = sc_render_match(scp, scp->sc->adp->va_name,
2857 scp->status & (GRAPHICS_MODE | PIXEL_MODE));
2862 if (sw == scp->tsw) {
2863 error = (*sw->te_init)(scp, &scp->ts, SC_TE_WARM_INIT);
2865 scp->rndr->init(scp);
2866 sc_clear_screen(scp);
2867 /* assert(error == 0); */
2871 if (sc_malloc && (sw->te_size > 0))
2872 p = malloc(sw->te_size, M_DEVBUF, M_NOWAIT);
2875 error = (*sw->te_init)(scp, &p, SC_TE_COLD_INIT);
2880 (*scp->tsw->te_term)(scp, &scp->ts);
2881 if (scp->ts != NULL)
2882 free(scp->ts, M_DEVBUF);
2886 scp->rndr->init(scp);
2889 (*sw->te_default_attr)(scp, user_default.std_color, user_default.rev_color);
2890 sc_clear_screen(scp);
2896 * scgetc(flags) - get character from keyboard.
2897 * If flags & SCGETC_CN, then avoid harmful side effects.
2898 * If flags & SCGETC_NONBLOCK, then wait until a key is pressed, else
2899 * return NOKEY if there is nothing there.
2902 scgetc(sc_softc_t *sc, u_int flags)
2905 #ifndef SC_NO_HISTORY
2913 if (sc->kbd == NULL)
2918 /* I don't like this, but... XXX */
2919 if (flags & SCGETC_CN)
2920 sccnupdate(sc->cur_scp);
2923 /* first see if there is something in the keyboard port */
2925 c = kbd_read_char(sc->kbd, !(flags & SCGETC_NONBLOCK));
2927 if (!(flags & SCGETC_CN))
2928 sc_bell(scp, bios_value.bell_pitch, BELL_DURATION);
2929 } else if (c == NOKEY)
2935 /* make screensaver happy */
2937 sc_touch_scrn_saver();
2939 if (!(flags & SCGETC_CN))
2940 /* do the /dev/random device a favour */
2941 add_keyboard_randomness(c);
2943 if (scp->kbd_mode != K_XLATE)
2946 /* if scroll-lock pressed allow history browsing */
2947 if (!ISGRAPHSC(scp) && scp->history && scp->status & SLKED) {
2949 scp->status &= ~CURSOR_ENABLED;
2950 sc_remove_cursor_image(scp);
2952 #ifndef SC_NO_HISTORY
2953 if (!(scp->status & BUFFER_SAVED)) {
2954 scp->status |= BUFFER_SAVED;
2958 /* FIXME: key codes */
2959 case SPCLKEY | FKEY | F(49): /* home key */
2960 sc_remove_cutmarking(scp);
2964 case SPCLKEY | FKEY | F(57): /* end key */
2965 sc_remove_cutmarking(scp);
2969 case SPCLKEY | FKEY | F(50): /* up arrow key */
2970 sc_remove_cutmarking(scp);
2971 if (sc_hist_up_line(scp))
2972 if (!(flags & SCGETC_CN))
2973 sc_bell(scp, bios_value.bell_pitch, BELL_DURATION);
2976 case SPCLKEY | FKEY | F(58): /* down arrow key */
2977 sc_remove_cutmarking(scp);
2978 if (sc_hist_down_line(scp))
2979 if (!(flags & SCGETC_CN))
2980 sc_bell(scp, bios_value.bell_pitch, BELL_DURATION);
2983 case SPCLKEY | FKEY | F(51): /* page up key */
2984 sc_remove_cutmarking(scp);
2985 for (i=0; i<scp->ysize; i++)
2986 if (sc_hist_up_line(scp)) {
2987 if (!(flags & SCGETC_CN))
2988 sc_bell(scp, bios_value.bell_pitch, BELL_DURATION);
2993 case SPCLKEY | FKEY | F(59): /* page down key */
2994 sc_remove_cutmarking(scp);
2995 for (i=0; i<scp->ysize; i++)
2996 if (sc_hist_down_line(scp)) {
2997 if (!(flags & SCGETC_CN))
2998 sc_bell(scp, bios_value.bell_pitch, BELL_DURATION);
3003 #endif /* SC_NO_HISTORY */
3007 * Process and consume special keys here. Return a plain char code
3008 * or a char code with the META flag or a function key code.
3012 /* goto next_code */
3017 switch (KEYCHAR(c)) {
3019 case NLK: case CLK: case ALK:
3022 kbd_ioctl(sc->kbd, KDGKBSTATE, (caddr_t)&f);
3024 scp->status |= SLKED;
3026 if (scp->status & SLKED) {
3027 scp->status &= ~SLKED;
3028 #ifndef SC_NO_HISTORY
3029 if (scp->status & BUFFER_SAVED) {
3030 if (!sc_hist_restore(scp))
3031 sc_remove_cutmarking(scp);
3032 scp->status &= ~BUFFER_SAVED;
3033 scp->status |= CURSOR_ENABLED;
3034 sc_draw_cursor_image(scp);
3036 tp = VIRTUAL_TTY(sc, scp->index);
3044 /* NON-LOCKING KEYS */
3046 case LSH: case RSH: case LCTR: case RCTR:
3047 case LALT: case RALT: case ASH: case META:
3051 if (!(sc->flags & SC_SCRN_BLANKED))
3057 /* force activatation/deactivation of the screen saver */
3058 if (!(sc->flags & SC_SCRN_BLANKED)) {
3059 run_scrn_saver = TRUE;
3060 sc->scrn_time_stamp -= scrn_blank_time;
3064 * While devices are being probed, the screen saver need
3065 * to be invoked explictly. XXX
3067 if (sc->flags & SC_SCRN_BLANKED) {
3068 scsplash_stick(FALSE);
3069 stop_scrn_saver(sc, current_saver);
3071 if (!ISGRAPHSC(scp)) {
3072 scsplash_stick(TRUE);
3073 (*current_saver)(sc, TRUE);
3077 #endif /* NSPLASH */
3081 #ifndef SC_DISABLE_REBOOT
3087 #ifndef SC_DISABLE_REBOOT
3088 shutdown_nice(RB_HALT);
3093 #ifndef SC_DISABLE_REBOOT
3094 shutdown_nice(RB_HALT|RB_POWEROFF);
3100 apm_suspend(PMST_SUSPEND);
3103 apm_suspend(PMST_STANDBY);
3112 #ifndef SC_DISABLE_DDBKEY
3114 Debugger("manual escape to debugger");
3116 printf("No debugger in kernel\n");
3118 #else /* SC_DISABLE_DDBKEY */
3120 #endif /* SC_DISABLE_DDBKEY */
3124 if (enable_panic_key)
3125 panic("Forced by the panic key");
3129 this_scr = scp->index;
3130 for (i = (this_scr - sc->first_vty + 1)%sc->vtys;
3131 sc->first_vty + i != this_scr;
3132 i = (i + 1)%sc->vtys) {
3133 struct tty *tp = VIRTUAL_TTY(sc, sc->first_vty + i);
3134 if (ISTTYOPEN(tp)) {
3135 sc_switch_scr(scp->sc, sc->first_vty + i);
3142 this_scr = scp->index;
3143 for (i = (this_scr - sc->first_vty + sc->vtys - 1)%sc->vtys;
3144 sc->first_vty + i != this_scr;
3145 i = (i + sc->vtys - 1)%sc->vtys) {
3146 struct tty *tp = VIRTUAL_TTY(sc, sc->first_vty + i);
3147 if (ISTTYOPEN(tp)) {
3148 sc_switch_scr(scp->sc, sc->first_vty + i);
3155 if (KEYCHAR(c) >= F_SCR && KEYCHAR(c) <= L_SCR) {
3156 sc_switch_scr(scp->sc, sc->first_vty + KEYCHAR(c) - F_SCR);
3159 /* assert(c & FKEY) */
3160 if (!(sc->flags & SC_SCRN_BLANKED))
3164 /* goto next_code */
3166 /* regular keys (maybe MKEY is set) */
3167 if (!(sc->flags & SC_SCRN_BLANKED))
3176 scmmap(dev_t dev, vm_offset_t offset, int nprot)
3181 if (scp != scp->sc->cur_scp)
3183 return (*vidsw[scp->sc->adapter]->mmap)(scp->sc->adp, offset, nprot);
3187 save_kbd_state(scr_stat *scp)
3192 error = kbd_ioctl(scp->sc->kbd, KDGKBSTATE, (caddr_t)&state);
3193 if (error == ENOIOCTL)
3196 scp->status &= ~LOCK_MASK;
3197 scp->status |= state;
3203 update_kbd_state(scr_stat *scp, int new_bits, int mask)
3208 if (mask != LOCK_MASK) {
3209 error = kbd_ioctl(scp->sc->kbd, KDGKBSTATE, (caddr_t)&state);
3210 if (error == ENOIOCTL)
3215 state |= new_bits & mask;
3217 state = new_bits & LOCK_MASK;
3219 error = kbd_ioctl(scp->sc->kbd, KDSKBSTATE, (caddr_t)&state);
3220 if (error == ENOIOCTL)
3226 update_kbd_leds(scr_stat *scp, int which)
3231 error = kbd_ioctl(scp->sc->kbd, KDSETLED, (caddr_t)&which);
3232 if (error == ENOIOCTL)
3238 set_mode(scr_stat *scp)
3242 /* reject unsupported mode */
3243 if ((*vidsw[scp->sc->adapter]->get_info)(scp->sc->adp, scp->mode, &info))
3246 /* if this vty is not currently showing, do nothing */
3247 if (scp != scp->sc->cur_scp)
3250 /* setup video hardware for the given mode */
3251 (*vidsw[scp->sc->adapter]->set_mode)(scp->sc->adp, scp->mode);
3252 scp->rndr->init(scp);
3253 sc_vtb_init(&scp->scr, VTB_FRAMEBUFFER, scp->xsize, scp->ysize,
3254 (void *)scp->sc->adp->va_window, FALSE);
3256 #ifndef SC_NO_FONT_LOADING
3257 /* load appropriate font */
3258 if (!(scp->status & GRAPHICS_MODE)) {
3259 if (!(scp->status & PIXEL_MODE) && ISFONTAVAIL(scp->sc->adp->va_flags)) {
3260 if (scp->font_size < 14) {
3261 if (scp->sc->fonts_loaded & FONT_8)
3262 sc_load_font(scp, 0, 8, scp->sc->font_8, 0, 256);
3263 } else if (scp->font_size >= 16) {
3264 if (scp->sc->fonts_loaded & FONT_16)
3265 sc_load_font(scp, 0, 16, scp->sc->font_16, 0, 256);
3267 if (scp->sc->fonts_loaded & FONT_14)
3268 sc_load_font(scp, 0, 14, scp->sc->font_14, 0, 256);
3272 * This is an interim kludge to display correct font.
3273 * Always use the font page #0 on the video plane 2.
3274 * Somehow we cannot show the font in other font pages on
3275 * some video cards... XXX
3277 sc_show_font(scp, 0);
3281 #endif /* !SC_NO_FONT_LOADING */
3283 sc_set_border(scp, scp->border);
3284 sc_set_cursor_image(scp);
3290 refresh_ega_palette(scr_stat *scp)
3294 int rsize, gsize, bsize;
3295 int rfld, gfld, bfld;
3298 rsize = scp->sc->adp->va_info.vi_pixel_fsizes[0];
3299 gsize = scp->sc->adp->va_info.vi_pixel_fsizes[1];
3300 bsize = scp->sc->adp->va_info.vi_pixel_fsizes[2];
3301 rfld = scp->sc->adp->va_info.vi_pixel_fields[0];
3302 gfld = scp->sc->adp->va_info.vi_pixel_fields[1];
3303 bfld = scp->sc->adp->va_info.vi_pixel_fields[2];
3305 for (i = 0; i < 16; i++) {
3306 reg = scp->sc->adp->va_palette_regs[i];
3308 r = scp->sc->palette[reg * 3] >> (8 - rsize);
3309 g = scp->sc->palette[reg * 3 + 1] >> (8 - gsize);
3310 b = scp->sc->palette[reg * 3 + 2] >> (8 - bsize);
3312 scp->ega_palette[i] = (r << rfld) + (g << gfld) + (b << bfld);
3317 sc_set_border(scr_stat *scp, int color)
3319 ++scp->sc->videoio_in_progress;
3320 (*scp->rndr->draw_border)(scp, color);
3321 --scp->sc->videoio_in_progress;
3324 #ifndef SC_NO_FONT_LOADING
3326 sc_load_font(scr_stat *scp, int page, int size, u_char *buf,
3327 int base, int count)
3332 sc->font_loading_in_progress = TRUE;
3333 (*vidsw[sc->adapter]->load_font)(sc->adp, page, size, buf, base, count);
3334 sc->font_loading_in_progress = FALSE;
3338 sc_save_font(scr_stat *scp, int page, int size, u_char *buf,
3339 int base, int count)
3344 sc->font_loading_in_progress = TRUE;
3345 (*vidsw[sc->adapter]->save_font)(sc->adp, page, size, buf, base, count);
3346 sc->font_loading_in_progress = FALSE;
3350 sc_show_font(scr_stat *scp, int page)
3352 (*vidsw[scp->sc->adapter]->show_font)(scp->sc->adp, page);
3354 #endif /* !SC_NO_FONT_LOADING */
3357 sc_paste(scr_stat *scp, u_char *p, int count)
3362 if (scp->status & MOUSE_VISIBLE) {
3363 tp = VIRTUAL_TTY(scp->sc, scp->sc->cur_scp->index);
3366 rmap = scp->sc->scr_rmap;
3367 for (; count > 0; --count)
3368 (*linesw[tp->t_line].l_rint)(rmap[*p++], tp);
3373 sc_bell(scr_stat *scp, int pitch, int duration)
3375 if (cold || shutdown_in_progress)
3378 if (scp != scp->sc->cur_scp && (scp->sc->flags & SC_QUIET_BELL))
3381 if (scp->sc->flags & SC_VISUAL_BELL) {
3382 if (scp->sc->blink_in_progress)
3384 scp->sc->blink_in_progress = 3;
3385 if (scp != scp->sc->cur_scp)
3386 scp->sc->blink_in_progress += 2;
3387 blink_screen(scp->sc->cur_scp);
3388 } else if (duration != 0 && pitch != 0) {
3389 if (scp != scp->sc->cur_scp)
3391 sysbeep(pitch, duration);
3396 blink_screen(void *arg)
3398 scr_stat *scp = arg;
3401 if (ISGRAPHSC(scp) || (scp->sc->blink_in_progress <= 1)) {
3402 scp->sc->blink_in_progress = 0;
3404 tp = VIRTUAL_TTY(scp->sc, scp->index);
3407 if (scp->sc->delayed_next_scr)
3408 sc_switch_scr(scp->sc, scp->sc->delayed_next_scr - 1);
3411 (*scp->rndr->draw)(scp, 0, scp->xsize*scp->ysize,
3412 scp->sc->blink_in_progress & 1);
3413 scp->sc->blink_in_progress--;
3414 callout_reset(&scp->blink_screen_ch, hz / 10, blink_screen, scp);