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.21 2005/05/27 07:52:21 swildner Exp $
35 #include "use_splash.h"
36 #include "opt_syscons.h"
40 #include <sys/param.h>
41 #include <sys/systm.h>
42 #include <sys/eventhandler.h>
43 #include <sys/reboot.h>
46 #include <sys/signalvar.h>
47 #include <sys/sysctl.h>
49 #include <sys/kernel.h>
51 #include <sys/random.h>
53 #include <machine/clock.h>
54 #include <machine/console.h>
55 #include <machine/psl.h>
56 #include <machine/pc/display.h>
57 #include <machine/apm_bios.h>
58 #include <machine/frame.h>
60 #include <dev/misc/kbd/kbdreg.h>
61 #include <dev/video/fb/fbreg.h>
62 #include <dev/video/fb/splashreg.h>
68 #define DEFAULT_BLANKTIME (5*60) /* 5 minutes */
69 #define MAX_BLANKTIME (7*24*60*60) /* 7 days!? */
71 #define KEYCODE_BS 0x0e /* "<-- Backspace" key, XXX */
73 MALLOC_DEFINE(M_SYSCONS, "syscons", "Syscons");
75 typedef struct default_attr {
76 int std_color; /* normal hardware color */
77 int rev_color; /* reverse hardware color */
80 static default_attr user_default = {
85 static default_attr kernel_default = {
87 SC_KERNEL_CONS_REV_ATTR,
90 static int sc_console_unit = -1;
91 static scr_stat *sc_console;
92 static struct tty *sc_console_tty;
93 static void *kernel_console_ts;
95 static char init_done = COLD;
96 static char shutdown_in_progress = FALSE;
97 static char sc_malloc = FALSE;
99 static int saver_mode = CONS_NO_SAVER; /* LKM/user saver */
100 static int run_scrn_saver = FALSE; /* should run the saver? */
101 static long scrn_blank_time = 0; /* screen saver timeout value */
103 static int scrn_blanked; /* # of blanked screen */
104 static int sticky_splash = FALSE;
106 static void none_saver(sc_softc_t *sc, int blank) { }
107 static void (*current_saver)(sc_softc_t *, int) = none_saver;
110 #if !defined(SC_NO_FONT_LOADING) && defined(SC_DFLT_FONT)
114 d_ioctl_t *sc_user_ioctl;
116 static bios_values_t bios_value;
118 static int enable_panic_key;
119 SYSCTL_INT(_machdep, OID_AUTO, enable_panic_key, CTLFLAG_RW, &enable_panic_key,
122 #define SC_CONSOLECTL 255
124 #define VIRTUAL_TTY(sc, x) (SC_DEV((sc), (x)) != NULL ? \
125 SC_DEV((sc), (x))->si_tty : NULL)
126 #define ISTTYOPEN(tp) ((tp) && ((tp)->t_state & TS_ISOPEN))
131 static int scvidprobe(int unit, int flags, int cons);
132 static int sckbdprobe(int unit, int flags, int cons);
133 static void scmeminit(void *arg);
134 static int scdevtounit(dev_t dev);
135 static kbd_callback_func_t sckbdevent;
136 static int scparam(struct tty *tp, struct termios *t);
137 static void scstart(struct tty *tp);
138 static void scinit(int unit, int flags);
139 static void scterm(int unit, int flags);
140 static void scshutdown(void *arg, int howto);
141 static u_int scgetc(sc_softc_t *sc, u_int flags);
143 #define SCGETC_NONBLOCK 2
144 static int sccngetch(int flags);
145 static void sccnupdate(scr_stat *scp);
146 static scr_stat *alloc_scp(sc_softc_t *sc, int vty);
147 static void init_scp(sc_softc_t *sc, int vty, scr_stat *scp);
148 static timeout_t scrn_timer;
149 static int and_region(int *s1, int *e1, int s2, int e2);
150 static void scrn_update(scr_stat *scp, int show_cursor);
153 static int scsplash_callback(int event, void *arg);
154 static void scsplash_saver(sc_softc_t *sc, int show);
155 static int add_scrn_saver(void (*this_saver)(sc_softc_t *, int));
156 static int remove_scrn_saver(void (*this_saver)(sc_softc_t *, int));
157 static int set_scrn_saver_mode(scr_stat *scp, int mode, u_char *pal, int border);
158 static int restore_scrn_saver_mode(scr_stat *scp, int changemode);
159 static void stop_scrn_saver(sc_softc_t *sc, void (*saver)(sc_softc_t *, int));
160 static int wait_scrn_saver_stop(sc_softc_t *sc);
161 #define scsplash_stick(stick) (sticky_splash = (stick))
163 #define scsplash_stick(stick)
166 static int do_switch_scr(sc_softc_t *sc, int s);
167 static int vt_proc_alive(scr_stat *scp);
168 static int signal_vt_rel(scr_stat *scp);
169 static int signal_vt_acq(scr_stat *scp);
170 static int finish_vt_rel(scr_stat *scp, int release, int *s);
171 static int finish_vt_acq(scr_stat *scp);
172 static void exchange_scr(sc_softc_t *sc);
173 static void update_cursor_image(scr_stat *scp);
174 static int save_kbd_state(scr_stat *scp);
175 static int update_kbd_state(scr_stat *scp, int state, int mask);
176 static int update_kbd_leds(scr_stat *scp, int which);
177 static timeout_t blink_screen;
179 #define CDEV_MAJOR 12
181 static cn_probe_t sccnprobe;
182 static cn_init_t sccninit;
183 static cn_getc_t sccngetc;
184 static cn_checkc_t sccncheckc;
185 static cn_putc_t sccnputc;
186 static cn_dbctl_t sccndbctl;
187 static cn_term_t sccnterm;
189 CONS_DRIVER(sc, sccnprobe, sccninit, sccnterm, sccngetc, sccncheckc, sccnputc,
192 static d_open_t scopen;
193 static d_close_t scclose;
194 static d_read_t scread;
195 static d_ioctl_t scioctl;
196 static d_mmap_t scmmap;
198 static struct cdevsw sc_cdevsw = {
200 /* maj */ CDEV_MAJOR,
201 /* flags */ D_TTY | D_KQFILTER,
208 /* write */ ttywrite,
212 /* strategy */ nostrategy,
215 /* kqfilter */ ttykqfilter
219 sc_probe_unit(int unit, int flags)
221 if (!scvidprobe(unit, flags, FALSE)) {
223 printf("sc%d: no video adapter found.\n", unit);
227 /* syscons will be attached even when there is no keyboard */
228 sckbdprobe(unit, flags, FALSE);
233 /* probe video adapters, return TRUE if found */
235 scvidprobe(int unit, int flags, int cons)
238 * Access the video adapter driver through the back door!
239 * Video adapter drivers need to be configured before syscons.
240 * However, when syscons is being probed as the low-level console,
241 * they have not been initialized yet. We force them to initialize
242 * themselves here. XXX
244 vid_configure(cons ? VIO_PROBE_ONLY : 0);
246 return (vid_find_adapter("*", unit) >= 0);
249 /* probe the keyboard, return TRUE if found */
251 sckbdprobe(int unit, int flags, int cons)
253 /* access the keyboard driver through the backdoor! */
254 kbd_configure(cons ? KB_CONF_PROBE_ONLY : 0);
256 return (kbd_find_keyboard("*", unit) >= 0);
260 *adapter_name(video_adapter_t *adp)
266 { KD_MONO, { "MDA", "MDA" } },
267 { KD_HERCULES, { "Hercules", "Hercules" } },
268 { KD_CGA, { "CGA", "CGA" } },
269 { KD_EGA, { "EGA", "EGA (mono)" } },
270 { KD_VGA, { "VGA", "VGA (mono)" } },
271 { KD_TGA, { "TGA", "TGA" } },
272 { -1, { "Unknown", "Unknown" } },
276 for (i = 0; names[i].type != -1; ++i)
277 if (names[i].type == adp->va_type)
279 return names[i].name[(adp->va_flags & V_ADP_COLOR) ? 0 : 1];
283 sc_attach_unit(int unit, int flags)
293 flags &= ~SC_KERNEL_CONSOLE;
295 if (sc_console_unit == unit) {
297 * If this unit is being used as the system console, we need to
298 * adjust some variables and buffers before and after scinit().
300 /* assert(sc_console != NULL) */
301 flags |= SC_KERNEL_CONSOLE;
306 if (sc_console->tsw->te_size > 0) {
307 /* assert(sc_console->ts != NULL); */
308 kernel_console_ts = sc_console->ts;
309 sc_console->ts = malloc(sc_console->tsw->te_size,
310 M_SYSCONS, M_WAITOK);
311 bcopy(kernel_console_ts, sc_console->ts, sc_console->tsw->te_size);
312 (*sc_console->tsw->te_default_attr)(sc_console,
313 user_default.std_color,
314 user_default.rev_color);
320 sc = sc_get_softc(unit, flags & SC_KERNEL_CONSOLE);
322 callout_init(&sc->scrn_timer_ch);
323 scp = SC_STAT(sc->dev[0]);
324 if (sc_console == NULL) /* sc_console_unit < 0 */
328 if ((sc->config & SC_VESA800X600)
329 && ((*vidsw[sc->adapter]->get_info)(sc->adp, M_VESA_800x600, &info) == 0)) {
331 if (sc->flags & SC_SPLASH_SCRN)
332 splash_term(sc->adp);
334 sc_set_graphics_mode(scp, NULL, M_VESA_800x600);
335 sc_set_pixel_mode(scp, NULL, COL, ROW, 16);
336 sc->initial_mode = M_VESA_800x600;
338 /* put up the splash again! */
339 if (sc->flags & SC_SPLASH_SCRN)
340 splash_init(sc->adp, scsplash_callback, sc);
343 #endif /* SC_PIXEL_MODE */
345 /* initialize cursor */
347 update_cursor_image(scp);
349 /* get screen update going */
352 /* set up the keyboard */
353 kbd_ioctl(sc->kbd, KDSKBMODE, (caddr_t)&scp->kbd_mode);
354 update_kbd_state(scp, scp->status, LOCK_MASK);
356 printf("sc%d: %s <%d virtual consoles, flags=0x%x>\n",
357 unit, adapter_name(sc->adp), sc->vtys, sc->config);
359 printf("sc%d:", unit);
360 if (sc->adapter >= 0)
361 printf(" fb%d", sc->adapter);
362 if (sc->keyboard >= 0)
363 printf(", kbd%d", sc->keyboard);
365 printf(", terminal emulator: %s (%s)",
366 scp->tsw->te_name, scp->tsw->te_desc);
370 /* register a shutdown callback for the kernel console */
371 if (sc_console_unit == unit)
372 EVENTHANDLER_REGISTER(shutdown_pre_sync, scshutdown,
373 (void *)(uintptr_t)unit, SHUTDOWN_PRI_DEFAULT);
376 * create devices. cdevsw_add() must be called to make devices under
377 * this major number available to userland.
379 cdevsw_add(&sc_cdevsw, ~(MAXCONS - 1), unit * MAXCONS);
381 for (vc = 0; vc < sc->vtys; vc++) {
382 dev = make_dev(&sc_cdevsw, vc + unit * MAXCONS,
383 UID_ROOT, GID_WHEEL, 0600, "ttyv%r", vc + unit * MAXCONS);
386 * The first vty already has struct tty and scr_stat initialized
387 * in scinit(). The other vtys will have these structs when
392 cdevsw_add(&sc_cdevsw, -1, SC_CONSOLECTL); /* XXX */
393 dev = make_dev(&sc_cdevsw, SC_CONSOLECTL,
394 UID_ROOT, GID_WHEEL, 0600, "consolectl");
395 dev->si_tty = sc_console_tty = ttymalloc(sc_console_tty);
396 dev->si_drv1 = sc_console;
409 * As soon as malloc() becomes functional, we had better allocate
410 * various buffers for the kernel console.
413 if (sc_console_unit < 0) /* sc_console == NULL */
416 /* copy the temporary buffer to the final buffer */
417 sc_alloc_scr_buffer(sc_console, TRUE, FALSE);
419 #ifndef SC_NO_CUTPASTE
420 sc_alloc_cut_buffer(sc_console, TRUE);
423 #ifndef SC_NO_HISTORY
424 /* initialize history buffer & pointers */
425 sc_alloc_history_buffer(sc_console, 0, 0, TRUE);
430 SYSINIT(sc_mem, SI_SUB_KMEM, SI_ORDER_ANY, scmeminit, NULL);
433 scdevtounit(dev_t dev)
435 int vty = SC_VTY(dev);
437 if (vty == SC_CONSOLECTL)
438 return ((sc_console != NULL) ? sc_console->sc->unit : -1);
439 else if ((vty < 0) || (vty >= MAXCONS*sc_max_unit()))
446 scopen(dev_t dev, int flag, int mode, struct thread *td)
448 int unit = scdevtounit(dev);
455 DPRINTF(5, ("scopen: dev:%d,%d, unit:%d, vty:%d\n",
456 major(dev), minor(dev), unit, SC_VTY(dev)));
458 sc = sc_get_softc(unit, (sc_console_unit == unit) ? SC_KERNEL_CONSOLE : 0);
462 tp = dev->si_tty = ttymalloc(dev->si_tty);
463 tp->t_oproc = scstart;
464 tp->t_param = scparam;
465 tp->t_stop = nottystop;
467 if (!ISTTYOPEN(tp)) {
469 /* Use the current setting of the <-- key as default VERASE. */
470 /* If the Delete key is preferable, an stty is necessary */
471 if (sc->kbd != NULL) {
472 key.keynum = KEYCODE_BS;
473 kbd_ioctl(sc->kbd, GIO_KEYMAPENT, (caddr_t)&key);
474 tp->t_cc[VERASE] = key.key.map[0];
476 tp->t_iflag = TTYDEF_IFLAG;
477 tp->t_oflag = TTYDEF_OFLAG;
478 tp->t_cflag = TTYDEF_CFLAG;
479 tp->t_lflag = TTYDEF_LFLAG;
480 tp->t_ispeed = tp->t_ospeed = TTYDEF_SPEED;
481 scparam(tp, &tp->t_termios);
482 (*linesw[tp->t_line].l_modem)(tp, 1);
485 if (tp->t_state & TS_XCLUDE && suser(td))
488 error = (*linesw[tp->t_line].l_open)(dev, tp);
492 scp = dev->si_drv1 = alloc_scp(sc, SC_VTY(dev));
494 sc_set_pixel_mode(scp, NULL, COL, ROW, 16);
496 if (!tp->t_winsize.ws_col && !tp->t_winsize.ws_row) {
497 tp->t_winsize.ws_col = scp->xsize;
498 tp->t_winsize.ws_row = scp->ysize;
505 scclose(dev_t dev, int flag, int mode, struct thread *td)
507 struct tty *tp = dev->si_tty;
511 if (SC_VTY(dev) != SC_CONSOLECTL) {
512 scp = SC_STAT(tp->t_dev);
513 /* were we in the middle of the VT switching process? */
514 DPRINTF(5, ("sc%d: scclose(), ", scp->sc->unit));
516 if ((scp == scp->sc->cur_scp) && (scp->sc->unit == sc_console_unit))
517 cons_unavail = FALSE;
518 if (finish_vt_rel(scp, TRUE, &s) == 0) /* force release */
519 DPRINTF(5, ("reset WAIT_REL, "));
520 if (finish_vt_acq(scp) == 0) /* force acknowledge */
521 DPRINTF(5, ("reset WAIT_ACQ, "));
523 if (scp == &main_console) {
526 scp->smode.mode = VT_AUTO;
529 sc_vtb_destroy(&scp->vtb);
530 sc_vtb_destroy(&scp->scr);
531 sc_free_history_buffer(scp, scp->ysize);
533 free(scp, M_SYSCONS);
538 scp->smode.mode = VT_AUTO;
540 scp->kbd_mode = K_XLATE;
541 if (scp == scp->sc->cur_scp)
542 kbd_ioctl(scp->sc->kbd, KDSKBMODE, (caddr_t)&scp->kbd_mode);
543 DPRINTF(5, ("done.\n"));
546 (*linesw[tp->t_line].l_close)(tp, flag);
553 scread(dev_t dev, struct uio *uio, int flag)
555 sc_touch_scrn_saver();
556 return ttyread(dev, uio, flag);
560 sckbdevent(keyboard_t *thiskbd, int event, void *arg)
568 sc = (sc_softc_t *)arg;
569 /* assert(thiskbd == sc->kbd) */
574 case KBDIO_UNLOADING:
577 kbd_release(thiskbd, (void *)&sc->keyboard);
584 * Loop while there is still input to get from the keyboard.
585 * I don't think this is nessesary, and it doesn't fix
586 * the Xaccel-2.1 keyboard hang, but it can't hurt. XXX
588 while ((c = scgetc(sc, SCGETC_NONBLOCK)) != NOKEY) {
590 cur_tty = VIRTUAL_TTY(sc, sc->cur_scp->index);
591 if (!ISTTYOPEN(cur_tty)) {
592 cur_tty = sc_console_tty;
593 if (!ISTTYOPEN(cur_tty))
597 if ((*sc->cur_scp->tsw->te_input)(sc->cur_scp, c, cur_tty))
600 switch (KEYFLAGS(c)) {
601 case 0x0000: /* normal key */
602 (*linesw[cur_tty->t_line].l_rint)(KEYCHAR(c), cur_tty);
604 case FKEY: /* function key, return string */
605 cp = kbd_get_fkeystr(thiskbd, KEYCHAR(c), &len);
608 (*linesw[cur_tty->t_line].l_rint)(*cp++, cur_tty);
611 case MKEY: /* meta is active, prepend ESC */
612 (*linesw[cur_tty->t_line].l_rint)(0x1b, cur_tty);
613 (*linesw[cur_tty->t_line].l_rint)(KEYCHAR(c), cur_tty);
615 case BKEY: /* backtab fixed sequence (esc [ Z) */
616 (*linesw[cur_tty->t_line].l_rint)(0x1b, cur_tty);
617 (*linesw[cur_tty->t_line].l_rint)('[', cur_tty);
618 (*linesw[cur_tty->t_line].l_rint)('Z', cur_tty);
623 sc->cur_scp->status |= MOUSE_HIDDEN;
629 scparam(struct tty *tp, struct termios *t)
631 tp->t_ispeed = t->c_ispeed;
632 tp->t_ospeed = t->c_ospeed;
633 tp->t_cflag = t->c_cflag;
638 scioctl(dev_t dev, u_long cmd, caddr_t data, int flag, struct thread *td)
646 struct proc *p = td->td_proc;
652 /* If there is a user_ioctl function call that first */
654 error = (*sc_user_ioctl)(dev, cmd, data, flag, td);
655 if (error != ENOIOCTL)
659 error = sc_vid_ioctl(tp, cmd, data, flag, td);
660 if (error != ENOIOCTL)
663 #ifndef SC_NO_HISTORY
664 error = sc_hist_ioctl(tp, cmd, data, flag, td);
665 if (error != ENOIOCTL)
669 #ifndef SC_NO_SYSMOUSE
670 error = sc_mouse_ioctl(tp, cmd, data, flag, td);
671 if (error != ENOIOCTL)
675 scp = SC_STAT(tp->t_dev);
676 /* assert(scp != NULL) */
677 /* scp is sc_console, if SC_VTY(dev) == SC_CONSOLECTL. */
681 error = (*scp->tsw->te_ioctl)(scp, tp, cmd, data, flag, td);
682 if (error != ENOIOCTL)
686 switch (cmd) { /* process console hardware related ioctl's */
688 case GIO_ATTR: /* get current attributes */
689 /* this ioctl is not processed here, but in the terminal emulator */
692 case GIO_COLOR: /* is this a color console ? */
693 *(int *)data = (sc->adp->va_flags & V_ADP_COLOR) ? 1 : 0;
696 case CONS_BLANKTIME: /* set screen saver timeout (0 = no saver) */
697 if (*(int *)data < 0 || *(int *)data > MAX_BLANKTIME)
700 scrn_blank_time = *(int *)data;
701 run_scrn_saver = (scrn_blank_time != 0);
705 case CONS_CURSORTYPE: /* set cursor type blink/noblink */
707 if (!ISGRAPHSC(sc->cur_scp))
708 sc_remove_cursor_image(sc->cur_scp);
709 if ((*(int*)data) & 0x01)
710 sc->flags |= SC_BLINK_CURSOR;
712 sc->flags &= ~SC_BLINK_CURSOR;
713 if ((*(int*)data) & 0x02) {
714 sc->flags |= SC_CHAR_CURSOR;
716 sc->flags &= ~SC_CHAR_CURSOR;
718 * The cursor shape is global property; all virtual consoles
719 * are affected. Update the cursor in the current console...
721 if (!ISGRAPHSC(sc->cur_scp)) {
722 sc_set_cursor_image(sc->cur_scp);
723 sc_draw_cursor_image(sc->cur_scp);
728 case CONS_BELLTYPE: /* set bell type sound/visual */
729 if ((*(int *)data) & 0x01)
730 sc->flags |= SC_VISUAL_BELL;
732 sc->flags &= ~SC_VISUAL_BELL;
733 if ((*(int *)data) & 0x02)
734 sc->flags |= SC_QUIET_BELL;
736 sc->flags &= ~SC_QUIET_BELL;
739 case CONS_GETINFO: /* get current (virtual) console info */
741 vid_info_t *ptr = (vid_info_t*)data;
742 if (ptr->size == sizeof(struct vid_info)) {
743 ptr->m_num = sc->cur_scp->index;
744 ptr->font_size = scp->font_size;
745 ptr->mv_col = scp->xpos;
746 ptr->mv_row = scp->ypos;
747 ptr->mv_csz = scp->xsize;
748 ptr->mv_rsz = scp->ysize;
750 * The following fields are filled by the terminal emulator. XXX
757 ptr->mv_grfc.fore = 0; /* not supported */
758 ptr->mv_grfc.back = 0; /* not supported */
759 ptr->mv_ovscan = scp->border;
760 if (scp == sc->cur_scp)
762 ptr->mk_keylock = scp->status & LOCK_MASK;
768 case CONS_GETVERS: /* get version number */
769 *(int*)data = 0x200; /* version 2.0 */
772 case CONS_IDLE: /* see if the screen has been idle */
774 * When the screen is in the GRAPHICS_MODE or UNKNOWN_MODE,
775 * the user process may have been writing something on the
776 * screen and syscons is not aware of it. Declare the screen
777 * is NOT idle if it is in one of these modes. But there is
778 * an exception to it; if a screen saver is running in the
779 * graphics mode in the current screen, we should say that the
780 * screen has been idle.
782 *(int *)data = (sc->flags & SC_SCRN_IDLE)
783 && (!ISGRAPHSC(sc->cur_scp)
784 || (sc->cur_scp->status & SAVER_RUNNING));
787 case CONS_SAVERMODE: /* set saver mode */
788 switch(*(int *)data) {
791 /* if a LKM screen saver is running, stop it first. */
792 scsplash_stick(FALSE);
793 saver_mode = *(int *)data;
796 if ((error = wait_scrn_saver_stop(NULL))) {
801 run_scrn_saver = TRUE;
802 if (saver_mode == CONS_USR_SAVER)
803 scp->status |= SAVER_RUNNING;
805 scp->status &= ~SAVER_RUNNING;
806 scsplash_stick(TRUE);
811 if ((saver_mode == CONS_USR_SAVER) && (scp->status & SAVER_RUNNING))
812 scp->status &= ~SAVER_RUNNING;
813 saver_mode = *(int *)data;
821 case CONS_SAVERSTART: /* immediately start/stop the screen saver */
823 * Note that this ioctl does not guarantee the screen saver
824 * actually starts or stops. It merely attempts to do so...
827 run_scrn_saver = (*(int *)data != 0);
829 sc->scrn_time_stamp -= scrn_blank_time;
833 case CONS_SCRSHOT: /* get a screen shot */
835 scrshot_t *ptr = (scrshot_t*)data;
837 if (ISGRAPHSC(scp)) {
841 if (scp->xsize != ptr->xsize || scp->ysize != ptr->ysize) {
845 copyout ((void*)scp->vtb.vtb_buffer, ptr->buf,
846 ptr->xsize * ptr->ysize * sizeof(uint16_t));
851 case VT_SETMODE: /* set screen switcher mode */
853 struct vt_mode *mode;
855 mode = (struct vt_mode *)data;
856 DPRINTF(5, ("sc%d: VT_SETMODE ", sc->unit));
857 if (scp->smode.mode == VT_PROCESS) {
858 if (scp->proc == pfind(scp->pid) && scp->proc != p) {
859 DPRINTF(5, ("error EPERM\n"));
864 if (mode->mode == VT_AUTO) {
865 scp->smode.mode = VT_AUTO;
868 DPRINTF(5, ("VT_AUTO, "));
869 if ((scp == sc->cur_scp) && (sc->unit == sc_console_unit))
870 cons_unavail = FALSE;
871 /* were we in the middle of the vty switching process? */
872 if (finish_vt_rel(scp, TRUE, &s) == 0)
873 DPRINTF(5, ("reset WAIT_REL, "));
874 if (finish_vt_acq(scp) == 0)
875 DPRINTF(5, ("reset WAIT_ACQ, "));
877 if (!ISSIGVALID(mode->relsig) || !ISSIGVALID(mode->acqsig)
878 || !ISSIGVALID(mode->frsig)) {
880 DPRINTF(5, ("error EINVAL\n"));
883 DPRINTF(5, ("VT_PROCESS %d, ", p->p_pid));
884 bcopy(data, &scp->smode, sizeof(struct vt_mode));
886 scp->pid = scp->proc->p_pid;
887 if ((scp == sc->cur_scp) && (sc->unit == sc_console_unit))
895 case VT_GETMODE: /* get screen switcher mode */
896 bcopy(&scp->smode, data, sizeof(struct vt_mode));
899 case VT_RELDISP: /* screen switcher ioctl */
902 * This must be the current vty which is in the VT_PROCESS
905 if ((scp != sc->cur_scp) || (scp->smode.mode != VT_PROCESS)) {
909 /* ...and this process is controlling it. */
910 if (scp->proc != p) {
915 switch(*(int *)data) {
916 case VT_FALSE: /* user refuses to release screen, abort */
917 if ((error = finish_vt_rel(scp, FALSE, &s)) == 0)
918 DPRINTF(5, ("sc%d: VT_FALSE\n", sc->unit));
920 case VT_TRUE: /* user has released screen, go on */
921 if ((error = finish_vt_rel(scp, TRUE, &s)) == 0)
922 DPRINTF(5, ("sc%d: VT_TRUE\n", sc->unit));
924 case VT_ACKACQ: /* acquire acknowledged, switch completed */
925 if ((error = finish_vt_acq(scp)) == 0)
926 DPRINTF(5, ("sc%d: VT_ACKACQ\n", sc->unit));
934 case VT_OPENQRY: /* return free virtual console */
935 for (i = sc->first_vty; i < sc->first_vty + sc->vtys; i++) {
936 tp = VIRTUAL_TTY(sc, i);
937 if (!ISTTYOPEN(tp)) {
938 *(int *)data = i + 1;
944 case VT_ACTIVATE: /* switch to screen *data */
945 i = (*(int *)data == 0) ? scp->index : (*(int *)data - 1);
947 sc_clean_up(sc->cur_scp);
949 return sc_switch_scr(sc, i);
951 case VT_WAITACTIVE: /* wait for switch to occur */
952 i = (*(int *)data == 0) ? scp->index : (*(int *)data - 1);
953 if ((i < sc->first_vty) || (i >= sc->first_vty + sc->vtys))
956 error = sc_clean_up(sc->cur_scp);
960 scp = SC_STAT(SC_DEV(sc, i));
961 if (scp == scp->sc->cur_scp)
963 while ((error=tsleep((caddr_t)&scp->smode, PCATCH,
964 "waitvt", 0)) == ERESTART) ;
967 case VT_GETACTIVE: /* get active vty # */
968 *(int *)data = sc->cur_scp->index + 1;
971 case VT_GETINDEX: /* get this vty # */
972 *(int *)data = scp->index + 1;
975 case VT_LOCKSWITCH: /* prevent vty switching */
976 if ((*(int *)data) & 0x01)
977 sc->flags |= SC_SCRN_VTYLOCK;
979 sc->flags &= ~SC_SCRN_VTYLOCK;
982 case KDENABIO: /* allow io operations */
988 p->p_md.md_regs->tf_eflags |= PSL_IOPL;
991 case KDDISABIO: /* disallow io operations (default) */
992 p->p_md.md_regs->tf_eflags &= ~PSL_IOPL;
995 case KDSKBSTATE: /* set keyboard state (locks) */
996 if (*(int *)data & ~LOCK_MASK)
998 scp->status &= ~LOCK_MASK;
999 scp->status |= *(int *)data;
1000 if (scp == sc->cur_scp)
1001 update_kbd_state(scp, scp->status, LOCK_MASK);
1004 case KDGKBSTATE: /* get keyboard state (locks) */
1005 if (scp == sc->cur_scp)
1006 save_kbd_state(scp);
1007 *(int *)data = scp->status & LOCK_MASK;
1010 case KDGETREPEAT: /* get keyboard repeat & delay rates */
1011 case KDSETREPEAT: /* set keyboard repeat & delay rates (new) */
1012 error = kbd_ioctl(sc->kbd, cmd, data);
1013 if (error == ENOIOCTL)
1017 case KDSETRAD: /* set keyboard repeat & delay rates (old) */
1018 if (*(int *)data & ~0x7f)
1020 error = kbd_ioctl(sc->kbd, cmd, data);
1021 if (error == ENOIOCTL)
1025 case KDSKBMODE: /* set keyboard mode */
1026 switch (*(int *)data) {
1027 case K_XLATE: /* switch to XLT ascii mode */
1028 case K_RAW: /* switch to RAW scancode mode */
1029 case K_CODE: /* switch to CODE mode */
1030 scp->kbd_mode = *(int *)data;
1031 if (scp == sc->cur_scp)
1032 kbd_ioctl(sc->kbd, cmd, data);
1039 case KDGKBMODE: /* get keyboard mode */
1040 *(int *)data = scp->kbd_mode;
1044 error = kbd_ioctl(sc->kbd, cmd, data);
1045 if (error == ENOIOCTL)
1049 case KDMKTONE: /* sound the bell */
1051 sc_bell(scp, (*(int*)data)&0xffff,
1052 (((*(int*)data)>>16)&0xffff)*hz/1000);
1054 sc_bell(scp, scp->bell_pitch, scp->bell_duration);
1057 case KIOCSOUND: /* make tone (*data) hz */
1058 if (scp == sc->cur_scp) {
1060 return sc_tone(*(int *)data);
1066 case KDGKBTYPE: /* get keyboard type */
1067 error = kbd_ioctl(sc->kbd, cmd, data);
1068 if (error == ENOIOCTL) {
1069 /* always return something? XXX */
1074 case KDSETLED: /* set keyboard LED status */
1075 if (*(int *)data & ~LED_MASK) /* FIXME: LOCK_MASK? */
1077 scp->status &= ~LED_MASK;
1078 scp->status |= *(int *)data;
1079 if (scp == sc->cur_scp)
1080 update_kbd_leds(scp, scp->status);
1083 case KDGETLED: /* get keyboard LED status */
1084 if (scp == sc->cur_scp)
1085 save_kbd_state(scp);
1086 *(int *)data = scp->status & LED_MASK;
1089 case CONS_SETKBD: /* set the new keyboard */
1094 newkbd = kbd_get_keyboard(*(int *)data);
1095 if (newkbd == NULL) {
1100 if (sc->kbd != newkbd) {
1101 i = kbd_allocate(newkbd->kb_name, newkbd->kb_unit,
1102 (void *)&sc->keyboard, sckbdevent, sc);
1103 /* i == newkbd->kb_index */
1105 if (sc->kbd != NULL) {
1106 save_kbd_state(sc->cur_scp);
1107 kbd_release(sc->kbd, (void *)&sc->keyboard);
1109 sc->kbd = kbd_get_keyboard(i); /* sc->kbd == newkbd */
1111 kbd_ioctl(sc->kbd, KDSKBMODE,
1112 (caddr_t)&sc->cur_scp->kbd_mode);
1113 update_kbd_state(sc->cur_scp, sc->cur_scp->status,
1116 error = EPERM; /* XXX */
1123 case CONS_RELKBD: /* release the current keyboard */
1126 if (sc->kbd != NULL) {
1127 save_kbd_state(sc->cur_scp);
1128 error = kbd_release(sc->kbd, (void *)&sc->keyboard);
1137 case CONS_GETTERM: /* get the current terminal emulator info */
1141 if (((term_info_t *)data)->ti_index == 0) {
1144 sw = sc_term_match_by_number(((term_info_t *)data)->ti_index);
1147 strncpy(((term_info_t *)data)->ti_name, sw->te_name,
1148 sizeof(((term_info_t *)data)->ti_name));
1149 strncpy(((term_info_t *)data)->ti_desc, sw->te_desc,
1150 sizeof(((term_info_t *)data)->ti_desc));
1151 ((term_info_t *)data)->ti_flags = 0;
1154 ((term_info_t *)data)->ti_name[0] = '\0';
1155 ((term_info_t *)data)->ti_desc[0] = '\0';
1156 ((term_info_t *)data)->ti_flags = 0;
1161 case CONS_SETTERM: /* set the current terminal emulator */
1163 error = sc_init_emulator(scp, ((term_info_t *)data)->ti_name);
1164 /* FIXME: what if scp == sc_console! XXX */
1168 case GIO_SCRNMAP: /* get output translation table */
1169 bcopy(&sc->scr_map, data, sizeof(sc->scr_map));
1172 case PIO_SCRNMAP: /* set output translation table */
1173 bcopy(data, &sc->scr_map, sizeof(sc->scr_map));
1174 for (i=0; i<sizeof(sc->scr_map); i++) {
1175 sc->scr_rmap[sc->scr_map[i]] = i;
1179 case GIO_KEYMAP: /* get keyboard translation table */
1180 case PIO_KEYMAP: /* set keyboard translation table */
1181 case GIO_DEADKEYMAP: /* get accent key translation table */
1182 case PIO_DEADKEYMAP: /* set accent key translation table */
1183 case GETFKEY: /* get function key string */
1184 case SETFKEY: /* set function key string */
1185 error = kbd_ioctl(sc->kbd, cmd, data);
1186 if (error == ENOIOCTL)
1190 #ifndef SC_NO_FONT_LOADING
1192 case PIO_FONT8x8: /* set 8x8 dot font */
1193 if (!ISFONTAVAIL(sc->adp->va_flags))
1195 bcopy(data, sc->font_8, 8*256);
1196 sc->fonts_loaded |= FONT_8;
1199 * Always use the font page #0. XXX
1200 * Don't load if the current font size is not 8x8.
1202 if (ISTEXTSC(sc->cur_scp) && (sc->cur_scp->font_size < 14))
1203 sc_load_font(sc->cur_scp, 0, 8, sc->font_8, 0, 256);
1206 case GIO_FONT8x8: /* get 8x8 dot font */
1207 if (!ISFONTAVAIL(sc->adp->va_flags))
1209 if (sc->fonts_loaded & FONT_8) {
1210 bcopy(sc->font_8, data, 8*256);
1216 case PIO_FONT8x14: /* set 8x14 dot font */
1217 if (!ISFONTAVAIL(sc->adp->va_flags))
1219 bcopy(data, sc->font_14, 14*256);
1220 sc->fonts_loaded |= FONT_14;
1223 * Always use the font page #0. XXX
1224 * Don't load if the current font size is not 8x14.
1226 if (ISTEXTSC(sc->cur_scp)
1227 && (sc->cur_scp->font_size >= 14)
1228 && (sc->cur_scp->font_size < 16))
1229 sc_load_font(sc->cur_scp, 0, 14, sc->font_14, 0, 256);
1232 case GIO_FONT8x14: /* get 8x14 dot font */
1233 if (!ISFONTAVAIL(sc->adp->va_flags))
1235 if (sc->fonts_loaded & FONT_14) {
1236 bcopy(sc->font_14, data, 14*256);
1242 case PIO_FONT8x16: /* set 8x16 dot font */
1243 if (!ISFONTAVAIL(sc->adp->va_flags))
1245 bcopy(data, sc->font_16, 16*256);
1246 sc->fonts_loaded |= FONT_16;
1249 * Always use the font page #0. XXX
1250 * Don't load if the current font size is not 8x16.
1252 if (ISTEXTSC(sc->cur_scp) && (sc->cur_scp->font_size >= 16))
1253 sc_load_font(sc->cur_scp, 0, 16, sc->font_16, 0, 256);
1256 case GIO_FONT8x16: /* get 8x16 dot font */
1257 if (!ISFONTAVAIL(sc->adp->va_flags))
1259 if (sc->fonts_loaded & FONT_16) {
1260 bcopy(sc->font_16, data, 16*256);
1266 #endif /* SC_NO_FONT_LOADING */
1272 error = (*linesw[tp->t_line].l_ioctl)(tp, cmd, data, flag, td);
1273 if (error != ENOIOCTL)
1275 error = ttioctl(tp, cmd, data, flag);
1276 if (error != ENOIOCTL)
1282 scstart(struct tty *tp)
1286 u_char buf[PCBURST];
1287 scr_stat *scp = SC_STAT(tp->t_dev);
1289 if (scp->status & SLKED ||
1290 (scp == scp->sc->cur_scp && scp->sc->blink_in_progress))
1293 if (!(tp->t_state & (TS_TIMEOUT | TS_BUSY | TS_TTSTOP))) {
1294 tp->t_state |= TS_BUSY;
1297 len = q_to_b(rbp, buf, PCBURST);
1299 sc_puts(scp, buf, len);
1302 tp->t_state &= ~TS_BUSY;
1309 sccnprobe(struct consdev *cp)
1314 cp->cn_pri = sc_get_cons_priority(&unit, &flags);
1316 /* a video card is always required */
1317 if (!scvidprobe(unit, flags, TRUE))
1318 cp->cn_pri = CN_DEAD;
1320 /* syscons will become console even when there is no keyboard */
1321 sckbdprobe(unit, flags, TRUE);
1323 if (cp->cn_pri == CN_DEAD)
1326 /* initialize required fields */
1327 cp->cn_dev = make_dev(&sc_cdevsw, SC_CONSOLECTL,
1328 UID_ROOT, GID_WHEEL, 0600, "consolectl");
1332 sccninit(struct consdev *cp)
1337 sc_get_cons_priority(&unit, &flags);
1338 scinit(unit, flags | SC_KERNEL_CONSOLE);
1339 sc_console_unit = unit;
1340 sc_console = SC_STAT(sc_get_softc(unit, SC_KERNEL_CONSOLE)->dev[0]);
1344 sccnterm(struct consdev *cp)
1346 /* we are not the kernel console any more, release everything */
1348 if (sc_console_unit < 0)
1349 return; /* shouldn't happen */
1352 sc_clear_screen(sc_console);
1353 sccnupdate(sc_console);
1355 scterm(sc_console_unit, SC_KERNEL_CONSOLE);
1356 sc_console_unit = -1;
1361 sccnputc(dev_t dev, int c)
1364 scr_stat *scp = sc_console;
1366 #ifndef SC_NO_HISTORY
1368 #endif /* !SC_NO_HISTORY */
1371 /* assert(sc_console != NULL) */
1373 #ifndef SC_NO_HISTORY
1374 if (scp == scp->sc->cur_scp && scp->status & SLKED) {
1375 scp->status &= ~SLKED;
1376 update_kbd_state(scp, scp->status, SLKED);
1377 if (scp->status & BUFFER_SAVED) {
1378 if (!sc_hist_restore(scp))
1379 sc_remove_cutmarking(scp);
1380 scp->status &= ~BUFFER_SAVED;
1381 scp->status |= CURSOR_ENABLED;
1382 sc_draw_cursor_image(scp);
1384 tp = VIRTUAL_TTY(scp->sc, scp->index);
1388 #endif /* !SC_NO_HISTORY */
1391 if (kernel_console_ts != NULL)
1392 scp->ts = kernel_console_ts;
1394 sc_puts(scp, buf, 1);
1397 s = spltty(); /* block sckbdevent and scrn_timer */
1405 return sccngetch(0);
1409 sccncheckc(dev_t dev)
1411 return sccngetch(SCGETC_NONBLOCK);
1415 sccndbctl(dev_t dev, int on)
1417 /* assert(sc_console_unit >= 0) */
1418 /* try to switch to the kernel console screen */
1419 if (on && debugger == 0) {
1421 * TRY to make sure the screen saver is stopped,
1422 * and the screen is updated before switching to
1427 && sc_console->sc->cur_scp->smode.mode == VT_AUTO
1428 && sc_console->smode.mode == VT_AUTO) {
1429 sc_console->sc->cur_scp->status |= MOUSE_HIDDEN;
1430 sc_switch_scr(sc_console->sc, sc_console->index);
1440 sccngetch(int flags)
1442 static struct fkeytab fkey;
1447 int s = spltty(); /* block sckbdevent and scrn_timer while we poll */
1450 /* assert(sc_console != NULL) */
1453 * Stop the screen saver and update the screen if necessary.
1454 * What if we have been running in the screen saver code... XXX
1456 sc_touch_scrn_saver();
1457 scp = sc_console->sc->cur_scp; /* XXX */
1460 if (fkeycp < fkey.len) {
1462 return fkey.str[fkeycp++];
1465 if (scp->sc->kbd == NULL) {
1471 * Make sure the keyboard is accessible even when the kbd device
1472 * driver is disabled.
1474 kbd_enable(scp->sc->kbd);
1476 /* we shall always use the keyboard in the XLATE mode here */
1477 cur_mode = scp->kbd_mode;
1478 scp->kbd_mode = K_XLATE;
1479 kbd_ioctl(scp->sc->kbd, KDSKBMODE, (caddr_t)&scp->kbd_mode);
1481 kbd_poll(scp->sc->kbd, TRUE);
1482 c = scgetc(scp->sc, SCGETC_CN | flags);
1483 kbd_poll(scp->sc->kbd, FALSE);
1485 scp->kbd_mode = cur_mode;
1486 kbd_ioctl(scp->sc->kbd, KDSKBMODE, (caddr_t)&scp->kbd_mode);
1487 kbd_disable(scp->sc->kbd);
1490 switch (KEYFLAGS(c)) {
1491 case 0: /* normal char */
1493 case FKEY: /* function key */
1494 p = kbd_get_fkeystr(scp->sc->kbd, KEYCHAR(c), (size_t *)&fkeycp);
1496 if ((p != NULL) && (fkey.len > 0)) {
1497 bcopy(p, fkey.str, fkey.len);
1511 sccnupdate(scr_stat *scp)
1513 /* this is a cut-down version of scrn_timer()... */
1515 if (scp->sc->font_loading_in_progress || scp->sc->videoio_in_progress)
1518 if (debugger > 0 || panicstr || shutdown_in_progress) {
1519 sc_touch_scrn_saver();
1520 } else if (scp != scp->sc->cur_scp) {
1524 if (!run_scrn_saver)
1525 scp->sc->flags &= ~SC_SCRN_IDLE;
1527 if ((saver_mode != CONS_LKM_SAVER) || !(scp->sc->flags & SC_SCRN_IDLE))
1528 if (scp->sc->flags & SC_SCRN_BLANKED)
1529 stop_scrn_saver(scp->sc, current_saver);
1530 #endif /* NSPLASH */
1532 if (scp != scp->sc->cur_scp || scp->sc->blink_in_progress
1533 || scp->sc->switch_in_progress)
1536 * FIXME: unlike scrn_timer(), we call scrn_update() from here even
1537 * when write_in_progress is non-zero. XXX
1540 if (!ISGRAPHSC(scp) && !(scp->sc->flags & SC_SCRN_BLANKED))
1541 scrn_update(scp, TRUE);
1545 scrn_timer(void *arg)
1547 static int kbd_interval = 0;
1554 again = (arg != NULL);
1556 sc = (sc_softc_t *)arg;
1557 else if (sc_console != NULL)
1558 sc = sc_console->sc;
1562 /* don't do anything when we are performing some I/O operations */
1563 if (sc->font_loading_in_progress || sc->videoio_in_progress) {
1565 callout_reset(&sc->scrn_timer_ch, hz / 10, scrn_timer, sc);
1570 if ((sc->kbd == NULL) && (sc->config & SC_AUTODETECT_KBD)) {
1571 /* try to allocate a keyboard automatically */
1572 if (++kbd_interval >= 25) {
1573 sc->keyboard = kbd_allocate("*", -1, (void *)&sc->keyboard,
1575 if (sc->keyboard >= 0) {
1576 sc->kbd = kbd_get_keyboard(sc->keyboard);
1577 kbd_ioctl(sc->kbd, KDSKBMODE,
1578 (caddr_t)&sc->cur_scp->kbd_mode);
1579 update_kbd_state(sc->cur_scp, sc->cur_scp->status,
1586 /* find the vty to update */
1589 /* should we stop the screen saver? */
1590 getmicrouptime(&tv);
1591 if (debugger > 0 || panicstr || shutdown_in_progress)
1592 sc_touch_scrn_saver();
1593 if (run_scrn_saver) {
1594 if (tv.tv_sec > sc->scrn_time_stamp + scrn_blank_time)
1595 sc->flags |= SC_SCRN_IDLE;
1597 sc->flags &= ~SC_SCRN_IDLE;
1599 sc->scrn_time_stamp = tv.tv_sec;
1600 sc->flags &= ~SC_SCRN_IDLE;
1601 if (scrn_blank_time > 0)
1602 run_scrn_saver = TRUE;
1605 if ((saver_mode != CONS_LKM_SAVER) || !(sc->flags & SC_SCRN_IDLE))
1606 if (sc->flags & SC_SCRN_BLANKED)
1607 stop_scrn_saver(sc, current_saver);
1608 #endif /* NSPLASH */
1610 /* should we just return ? */
1611 if (sc->blink_in_progress || sc->switch_in_progress
1612 || sc->write_in_progress) {
1614 callout_reset(&sc->scrn_timer_ch, hz / 10, scrn_timer, sc);
1619 /* Update the screen */
1620 scp = sc->cur_scp; /* cur_scp may have changed... */
1621 if (!ISGRAPHSC(scp) && !(sc->flags & SC_SCRN_BLANKED))
1622 scrn_update(scp, TRUE);
1625 /* should we activate the screen saver? */
1626 if ((saver_mode == CONS_LKM_SAVER) && (sc->flags & SC_SCRN_IDLE))
1627 if (!ISGRAPHSC(scp) || (sc->flags & SC_SCRN_BLANKED))
1628 (*current_saver)(sc, TRUE);
1629 #endif /* NSPLASH */
1632 callout_reset(&sc->scrn_timer_ch, hz / 25, scrn_timer, sc);
1637 and_region(int *s1, int *e1, int s2, int e2)
1639 if (*e1 < s2 || e2 < *s1)
1641 *s1 = imax(*s1, s2);
1642 *e1 = imin(*e1, e2);
1647 scrn_update(scr_stat *scp, int show_cursor)
1654 /* assert(scp == scp->sc->cur_scp) */
1656 ++scp->sc->videoio_in_progress;
1658 #ifndef SC_NO_CUTPASTE
1659 /* remove the previous mouse pointer image if necessary */
1660 if (scp->status & MOUSE_VISIBLE) {
1662 e = scp->mouse_pos + scp->xsize + 1;
1663 if ((scp->status & (MOUSE_MOVED | MOUSE_HIDDEN))
1664 || and_region(&s, &e, scp->start, scp->end)
1665 || ((scp->status & CURSOR_ENABLED) &&
1666 (scp->cursor_pos != scp->cursor_oldpos) &&
1667 (and_region(&s, &e, scp->cursor_pos, scp->cursor_pos)
1668 || and_region(&s, &e, scp->cursor_oldpos, scp->cursor_oldpos)))) {
1669 sc_remove_mouse_image(scp);
1670 if (scp->end >= scp->xsize*scp->ysize)
1671 scp->end = scp->xsize*scp->ysize - 1;
1674 #endif /* !SC_NO_CUTPASTE */
1678 if (scp->end >= scp->xsize*scp->ysize) {
1679 printf("scrn_update(): scp->end %d > size_of_screen!!\n", scp->end);
1680 scp->end = scp->xsize*scp->ysize - 1;
1682 if (scp->start < 0) {
1683 printf("scrn_update(): scp->start %d < 0\n", scp->start);
1688 /* update screen image */
1689 if (scp->start <= scp->end) {
1690 if (scp->mouse_cut_end >= 0) {
1691 /* there is a marked region for cut & paste */
1692 if (scp->mouse_cut_start <= scp->mouse_cut_end) {
1693 start = scp->mouse_cut_start;
1694 end = scp->mouse_cut_end;
1696 start = scp->mouse_cut_end;
1697 end = scp->mouse_cut_start - 1;
1701 /* does the cut-mark region overlap with the update region? */
1702 if (and_region(&s, &e, scp->start, scp->end)) {
1703 (*scp->rndr->draw)(scp, s, e - s + 1, TRUE);
1706 if (and_region(&s, &e, scp->start, scp->end))
1707 (*scp->rndr->draw)(scp, s, e - s + 1, FALSE);
1709 e = scp->xsize*scp->ysize - 1;
1710 if (and_region(&s, &e, scp->start, scp->end))
1711 (*scp->rndr->draw)(scp, s, e - s + 1, FALSE);
1713 (*scp->rndr->draw)(scp, scp->start,
1714 scp->end - scp->start + 1, FALSE);
1717 (*scp->rndr->draw)(scp, scp->start,
1718 scp->end - scp->start + 1, FALSE);
1722 /* we are not to show the cursor and the mouse pointer... */
1725 scp->start = scp->xsize*scp->ysize - 1;
1726 --scp->sc->videoio_in_progress;
1730 /* update cursor image */
1731 if (scp->status & CURSOR_ENABLED) {
1734 /* did cursor move since last time ? */
1735 if (scp->cursor_pos != scp->cursor_oldpos) {
1736 /* do we need to remove old cursor image ? */
1737 if (!and_region(&s, &e, scp->cursor_oldpos, scp->cursor_oldpos))
1738 sc_remove_cursor_image(scp);
1739 sc_draw_cursor_image(scp);
1741 if (and_region(&s, &e, scp->cursor_pos, scp->cursor_pos))
1742 /* cursor didn't move, but has been overwritten */
1743 sc_draw_cursor_image(scp);
1744 else if (scp->sc->flags & SC_BLINK_CURSOR)
1745 /* if it's a blinking cursor, update it */
1746 (*scp->rndr->blink_cursor)(scp, scp->cursor_pos,
1747 sc_inside_cutmark(scp,
1752 #ifndef SC_NO_CUTPASTE
1753 /* update "pseudo" mouse pointer image */
1754 if (scp->sc->flags & SC_MOUSE_ENABLED) {
1755 if (!(scp->status & (MOUSE_VISIBLE | MOUSE_HIDDEN))) {
1756 scp->status &= ~MOUSE_MOVED;
1757 sc_draw_mouse_image(scp);
1760 #endif /* SC_NO_CUTPASTE */
1763 scp->start = scp->xsize*scp->ysize - 1;
1765 --scp->sc->videoio_in_progress;
1770 scsplash_callback(int event, void *arg)
1775 sc = (sc_softc_t *)arg;
1779 if (add_scrn_saver(scsplash_saver) == 0) {
1780 sc->flags &= ~SC_SAVER_FAILED;
1781 run_scrn_saver = TRUE;
1782 if (cold && !(boothowto & (RB_VERBOSE | RB_CONFIG))) {
1783 scsplash_stick(TRUE);
1784 (*current_saver)(sc, TRUE);
1790 if (current_saver == scsplash_saver) {
1791 scsplash_stick(FALSE);
1792 error = remove_scrn_saver(scsplash_saver);
1804 scsplash_saver(sc_softc_t *sc, int show)
1806 static int busy = FALSE;
1815 if (!(sc->flags & SC_SAVER_FAILED)) {
1816 if (!(sc->flags & SC_SCRN_BLANKED))
1817 set_scrn_saver_mode(scp, -1, NULL, 0);
1818 switch (splash(sc->adp, TRUE)) {
1819 case 0: /* succeeded */
1821 case EAGAIN: /* try later */
1822 restore_scrn_saver_mode(scp, FALSE);
1823 sc_touch_scrn_saver(); /* XXX */
1826 sc->flags |= SC_SAVER_FAILED;
1827 scsplash_stick(FALSE);
1828 restore_scrn_saver_mode(scp, TRUE);
1829 printf("scsplash_saver(): failed to put up the image\n");
1833 } else if (!sticky_splash) {
1834 if ((sc->flags & SC_SCRN_BLANKED) && (splash(sc->adp, FALSE) == 0))
1835 restore_scrn_saver_mode(scp, TRUE);
1841 add_scrn_saver(void (*this_saver)(sc_softc_t *, int))
1846 if (current_saver != none_saver) {
1847 error = remove_scrn_saver(current_saver);
1852 if (current_saver != none_saver)
1855 run_scrn_saver = FALSE;
1856 saver_mode = CONS_LKM_SAVER;
1857 current_saver = this_saver;
1862 remove_scrn_saver(void (*this_saver)(sc_softc_t *, int))
1864 if (current_saver != this_saver)
1869 * In order to prevent `current_saver' from being called by
1870 * the timeout routine `scrn_timer()' while we manipulate
1871 * the saver list, we shall set `current_saver' to `none_saver'
1872 * before stopping the current saver, rather than blocking by `splXX()'.
1874 current_saver = none_saver;
1876 stop_scrn_saver(this_saver);
1879 /* unblank all blanked screens */
1880 wait_scrn_saver_stop(NULL);
1884 current_saver = none_saver;
1889 set_scrn_saver_mode(scr_stat *scp, int mode, u_char *pal, int border)
1893 /* assert(scp == scp->sc->cur_scp) */
1895 if (!ISGRAPHSC(scp))
1896 sc_remove_cursor_image(scp);
1897 scp->splash_save_mode = scp->mode;
1898 scp->splash_save_status = scp->status & (GRAPHICS_MODE | PIXEL_MODE);
1899 scp->status &= ~(GRAPHICS_MODE | PIXEL_MODE);
1900 scp->status |= (UNKNOWN_MODE | SAVER_RUNNING);
1901 scp->sc->flags |= SC_SCRN_BLANKED;
1907 if (set_mode(scp) == 0) {
1908 if (scp->sc->adp->va_info.vi_flags & V_INFO_GRAPHICS)
1909 scp->status |= GRAPHICS_MODE;
1910 #ifndef SC_NO_PALETTE_LOADING
1912 load_palette(scp->sc->adp, pal);
1914 sc_set_border(scp, border);
1918 scp->mode = scp->splash_save_mode;
1919 scp->status &= ~(UNKNOWN_MODE | SAVER_RUNNING);
1920 scp->status |= scp->splash_save_status;
1927 restore_scrn_saver_mode(scr_stat *scp, int changemode)
1933 /* assert(scp == scp->sc->cur_scp) */
1936 status = scp->status;
1937 scp->mode = scp->splash_save_mode;
1938 scp->status &= ~(UNKNOWN_MODE | SAVER_RUNNING);
1939 scp->status |= scp->splash_save_status;
1940 scp->sc->flags &= ~SC_SCRN_BLANKED;
1942 if (!ISGRAPHSC(scp))
1943 sc_draw_cursor_image(scp);
1948 if (set_mode(scp) == 0) {
1949 #ifndef SC_NO_PALETTE_LOADING
1950 load_palette(scp->sc->adp, scp->sc->palette);
1957 scp->status = status;
1964 stop_scrn_saver(sc_softc_t *sc, void (*saver)(sc_softc_t *, int))
1966 (*saver)(sc, FALSE);
1967 run_scrn_saver = FALSE;
1968 /* the screen saver may have chosen not to stop after all... */
1969 if (sc->flags & SC_SCRN_BLANKED)
1972 mark_all(sc->cur_scp);
1973 if (sc->delayed_next_scr)
1974 sc_switch_scr(sc, sc->delayed_next_scr - 1);
1975 wakeup((caddr_t)&scrn_blanked);
1979 wait_scrn_saver_stop(sc_softc_t *sc)
1983 while (scrn_blanked > 0) {
1984 run_scrn_saver = FALSE;
1985 if (sc && !(sc->flags & SC_SCRN_BLANKED)) {
1989 error = tsleep((caddr_t)&scrn_blanked, PCATCH, "scrsav", 0);
1990 if ((error != 0) && (error != ERESTART))
1993 run_scrn_saver = FALSE;
1996 #endif /* NSPLASH */
1999 sc_touch_scrn_saver(void)
2001 scsplash_stick(FALSE);
2002 run_scrn_saver = FALSE;
2006 sc_switch_scr(sc_softc_t *sc, u_int next_scr)
2012 DPRINTF(5, ("sc0: sc_switch_scr() %d ", next_scr + 1));
2014 /* prevent switch if previously requested */
2015 if (sc->flags & SC_SCRN_VTYLOCK) {
2016 sc_bell(sc->cur_scp, sc->cur_scp->bell_pitch,
2017 sc->cur_scp->bell_duration);
2021 /* delay switch if the screen is blanked or being updated */
2022 if ((sc->flags & SC_SCRN_BLANKED) || sc->write_in_progress
2023 || sc->blink_in_progress || sc->videoio_in_progress) {
2024 sc->delayed_next_scr = next_scr + 1;
2025 sc_touch_scrn_saver();
2026 DPRINTF(5, ("switch delayed\n"));
2031 cur_scp = sc->cur_scp;
2033 /* we are in the middle of the vty switching process... */
2034 if (sc->switch_in_progress
2035 && (cur_scp->smode.mode == VT_PROCESS)
2037 if (cur_scp->proc != pfind(cur_scp->pid)) {
2039 * The controlling process has died!!. Do some clean up.
2040 * NOTE:`cur_scp->proc' and `cur_scp->smode.mode'
2041 * are not reset here yet; they will be cleared later.
2043 DPRINTF(5, ("cur_scp controlling process %d died, ",
2045 if (cur_scp->status & SWITCH_WAIT_REL) {
2047 * Force the previous switch to finish, but return now
2050 DPRINTF(5, ("reset WAIT_REL, "));
2051 finish_vt_rel(cur_scp, TRUE, &s);
2053 DPRINTF(5, ("finishing previous switch\n"));
2055 } else if (cur_scp->status & SWITCH_WAIT_ACQ) {
2056 /* let's assume screen switch has been completed. */
2057 DPRINTF(5, ("reset WAIT_ACQ, "));
2058 finish_vt_acq(cur_scp);
2061 * We are in between screen release and acquisition, and
2062 * reached here via scgetc() or scrn_timer() which has
2063 * interrupted exchange_scr(). Don't do anything stupid.
2065 DPRINTF(5, ("waiting nothing, "));
2069 * The controlling process is alive, but not responding...
2070 * It is either buggy or it may be just taking time.
2071 * The following code is a gross kludge to cope with this
2072 * problem for which there is no clean solution. XXX
2074 if (cur_scp->status & SWITCH_WAIT_REL) {
2075 switch (sc->switch_in_progress++) {
2079 DPRINTF(5, ("sending relsig again, "));
2080 signal_vt_rel(cur_scp);
2087 * Act as if the controlling program returned
2090 DPRINTF(5, ("force reset WAIT_REL, "));
2091 finish_vt_rel(cur_scp, FALSE, &s);
2093 DPRINTF(5, ("act as if VT_FALSE was seen\n"));
2096 } else if (cur_scp->status & SWITCH_WAIT_ACQ) {
2097 switch (sc->switch_in_progress++) {
2101 DPRINTF(5, ("sending acqsig again, "));
2102 signal_vt_acq(cur_scp);
2108 /* clear the flag and finish the previous switch */
2109 DPRINTF(5, ("force reset WAIT_ACQ, "));
2110 finish_vt_acq(cur_scp);
2118 * Return error if an invalid argument is given, or vty switch
2119 * is still in progress.
2121 if ((next_scr < sc->first_vty) || (next_scr >= sc->first_vty + sc->vtys)
2122 || sc->switch_in_progress) {
2124 sc_bell(cur_scp, bios_value.bell_pitch, BELL_DURATION);
2125 DPRINTF(5, ("error 1\n"));
2130 * Don't allow switching away from the graphics mode vty
2131 * if the switch mode is VT_AUTO, unless the next vty is the same
2132 * as the current or the current vty has been closed (but showing).
2134 tp = VIRTUAL_TTY(sc, cur_scp->index);
2135 if ((cur_scp->index != next_scr)
2137 && (cur_scp->smode.mode == VT_AUTO)
2138 && ISGRAPHSC(cur_scp)) {
2140 sc_bell(cur_scp, bios_value.bell_pitch, BELL_DURATION);
2141 DPRINTF(5, ("error, graphics mode\n"));
2146 * Is the wanted vty open? Don't allow switching to a closed vty.
2147 * If we are in DDB, don't switch to a vty in the VT_PROCESS mode.
2148 * Note that we always allow the user to switch to the kernel
2149 * console even if it is closed.
2151 if ((sc_console == NULL) || (next_scr != sc_console->index)) {
2152 tp = VIRTUAL_TTY(sc, next_scr);
2153 if (!ISTTYOPEN(tp)) {
2155 sc_bell(cur_scp, bios_value.bell_pitch, BELL_DURATION);
2156 DPRINTF(5, ("error 2, requested vty isn't open!\n"));
2159 if ((debugger > 0) && (SC_STAT(tp->t_dev)->smode.mode == VT_PROCESS)) {
2161 DPRINTF(5, ("error 3, requested vty is in the VT_PROCESS mode\n"));
2166 /* this is the start of vty switching process... */
2167 ++sc->switch_in_progress;
2168 sc->delayed_next_scr = 0;
2169 sc->old_scp = cur_scp;
2170 sc->new_scp = SC_STAT(SC_DEV(sc, next_scr));
2171 if (sc->new_scp == sc->old_scp) {
2172 sc->switch_in_progress = 0;
2173 wakeup((caddr_t)&sc->new_scp->smode);
2175 DPRINTF(5, ("switch done (new == old)\n"));
2179 /* has controlling process died? */
2180 vt_proc_alive(sc->old_scp);
2181 vt_proc_alive(sc->new_scp);
2183 /* wait for the controlling process to release the screen, if necessary */
2184 if (signal_vt_rel(sc->old_scp)) {
2189 /* go set up the new vty screen */
2194 /* wake up processes waiting for this vty */
2195 wakeup((caddr_t)&sc->cur_scp->smode);
2197 /* wait for the controlling process to acknowledge, if necessary */
2198 if (signal_vt_acq(sc->cur_scp)) {
2203 sc->switch_in_progress = 0;
2204 if (sc->unit == sc_console_unit)
2205 cons_unavail = FALSE;
2207 DPRINTF(5, ("switch done\n"));
2213 do_switch_scr(sc_softc_t *sc, int s)
2215 vt_proc_alive(sc->new_scp);
2220 /* sc->cur_scp == sc->new_scp */
2221 wakeup((caddr_t)&sc->cur_scp->smode);
2223 /* wait for the controlling process to acknowledge, if necessary */
2224 if (!signal_vt_acq(sc->cur_scp)) {
2225 sc->switch_in_progress = 0;
2226 if (sc->unit == sc_console_unit)
2227 cons_unavail = FALSE;
2234 vt_proc_alive(scr_stat *scp)
2237 if (scp->proc == pfind(scp->pid))
2240 scp->smode.mode = VT_AUTO;
2241 DPRINTF(5, ("vt controlling process %d died\n", scp->pid));
2247 signal_vt_rel(scr_stat *scp)
2249 if (scp->smode.mode != VT_PROCESS)
2251 scp->status |= SWITCH_WAIT_REL;
2252 psignal(scp->proc, scp->smode.relsig);
2253 DPRINTF(5, ("sending relsig to %d\n", scp->pid));
2258 signal_vt_acq(scr_stat *scp)
2260 if (scp->smode.mode != VT_PROCESS)
2262 if (scp->sc->unit == sc_console_unit)
2263 cons_unavail = TRUE;
2264 scp->status |= SWITCH_WAIT_ACQ;
2265 psignal(scp->proc, scp->smode.acqsig);
2266 DPRINTF(5, ("sending acqsig to %d\n", scp->pid));
2271 finish_vt_rel(scr_stat *scp, int release, int *s)
2273 if (scp == scp->sc->old_scp && scp->status & SWITCH_WAIT_REL) {
2274 scp->status &= ~SWITCH_WAIT_REL;
2276 *s = do_switch_scr(scp->sc, *s);
2278 scp->sc->switch_in_progress = 0;
2285 finish_vt_acq(scr_stat *scp)
2287 if (scp == scp->sc->new_scp && scp->status & SWITCH_WAIT_ACQ) {
2288 scp->status &= ~SWITCH_WAIT_ACQ;
2289 scp->sc->switch_in_progress = 0;
2296 exchange_scr(sc_softc_t *sc)
2300 /* save the current state of video and keyboard */
2301 sc_move_cursor(sc->old_scp, sc->old_scp->xpos, sc->old_scp->ypos);
2302 if (!ISGRAPHSC(sc->old_scp))
2303 sc_remove_cursor_image(sc->old_scp);
2304 if (sc->old_scp->kbd_mode == K_XLATE)
2305 save_kbd_state(sc->old_scp);
2307 /* set up the video for the new screen */
2308 scp = sc->cur_scp = sc->new_scp;
2309 if (sc->old_scp->mode != scp->mode || ISUNKNOWNSC(sc->old_scp))
2312 sc_vtb_init(&scp->scr, VTB_FRAMEBUFFER, scp->xsize, scp->ysize,
2313 (void *)sc->adp->va_window, FALSE);
2314 scp->status |= MOUSE_HIDDEN;
2315 sc_move_cursor(scp, scp->xpos, scp->ypos);
2316 if (!ISGRAPHSC(scp))
2317 sc_set_cursor_image(scp);
2318 #ifndef SC_NO_PALETTE_LOADING
2319 if (ISGRAPHSC(sc->old_scp))
2320 load_palette(sc->adp, sc->palette);
2322 sc_set_border(scp, scp->border);
2324 /* set up the keyboard for the new screen */
2325 if (sc->old_scp->kbd_mode != scp->kbd_mode)
2326 kbd_ioctl(sc->kbd, KDSKBMODE, (caddr_t)&scp->kbd_mode);
2327 update_kbd_state(scp, scp->status, LOCK_MASK);
2333 sc_puts(scr_stat *scp, u_char *buf, int len)
2336 /* make screensaver happy */
2337 if (!sticky_splash && scp == scp->sc->cur_scp)
2338 run_scrn_saver = FALSE;
2342 (*scp->tsw->te_puts)(scp, buf, len);
2344 if (scp->sc->delayed_next_scr)
2345 sc_switch_scr(scp->sc, scp->sc->delayed_next_scr - 1);
2349 sc_draw_cursor_image(scr_stat *scp)
2351 /* assert(scp == scp->sc->cur_scp); */
2352 ++scp->sc->videoio_in_progress;
2353 (*scp->rndr->draw_cursor)(scp, scp->cursor_pos,
2354 scp->sc->flags & SC_BLINK_CURSOR, TRUE,
2355 sc_inside_cutmark(scp, scp->cursor_pos));
2356 scp->cursor_oldpos = scp->cursor_pos;
2357 --scp->sc->videoio_in_progress;
2361 sc_remove_cursor_image(scr_stat *scp)
2363 /* assert(scp == scp->sc->cur_scp); */
2364 ++scp->sc->videoio_in_progress;
2365 (*scp->rndr->draw_cursor)(scp, scp->cursor_oldpos,
2366 scp->sc->flags & SC_BLINK_CURSOR, FALSE,
2367 sc_inside_cutmark(scp, scp->cursor_oldpos));
2368 --scp->sc->videoio_in_progress;
2372 update_cursor_image(scr_stat *scp)
2376 if (scp->sc->flags & SC_CHAR_CURSOR) {
2377 scp->cursor_base = imax(0, scp->sc->cursor_base);
2378 scp->cursor_height = imin(scp->sc->cursor_height, scp->font_size);
2380 scp->cursor_base = 0;
2381 scp->cursor_height = scp->font_size;
2383 blink = scp->sc->flags & SC_BLINK_CURSOR;
2385 /* assert(scp == scp->sc->cur_scp); */
2386 ++scp->sc->videoio_in_progress;
2387 (*scp->rndr->draw_cursor)(scp, scp->cursor_oldpos, blink, FALSE,
2388 sc_inside_cutmark(scp, scp->cursor_pos));
2389 (*scp->rndr->set_cursor)(scp, scp->cursor_base, scp->cursor_height, blink);
2390 (*scp->rndr->draw_cursor)(scp, scp->cursor_pos, blink, TRUE,
2391 sc_inside_cutmark(scp, scp->cursor_pos));
2392 --scp->sc->videoio_in_progress;
2396 sc_set_cursor_image(scr_stat *scp)
2398 if (scp->sc->flags & SC_CHAR_CURSOR) {
2399 scp->cursor_base = imax(0, scp->sc->cursor_base);
2400 scp->cursor_height = imin(scp->sc->cursor_height, scp->font_size);
2402 scp->cursor_base = 0;
2403 scp->cursor_height = scp->font_size;
2406 /* assert(scp == scp->sc->cur_scp); */
2407 ++scp->sc->videoio_in_progress;
2408 (*scp->rndr->set_cursor)(scp, scp->cursor_base, scp->cursor_height,
2409 scp->sc->flags & SC_BLINK_CURSOR);
2410 --scp->sc->videoio_in_progress;
2414 scinit(int unit, int flags)
2417 * When syscons is being initialized as the kernel console, malloc()
2418 * is not yet functional, because various kernel structures has not been
2419 * fully initialized yet. Therefore, we need to declare the following
2420 * static buffers for the console. This is less than ideal,
2421 * but is necessry evil for the time being. XXX
2423 static scr_stat main_console;
2424 static dev_t main_devs[MAXCONS];
2425 static struct tty main_tty;
2426 static u_short sc_buffer[ROW*COL]; /* XXX */
2427 #ifndef SC_NO_FONT_LOADING
2428 static u_char font_8[256*8];
2429 static u_char font_14[256*14];
2430 static u_char font_16[256*16];
2435 video_adapter_t *adp;
2440 /* one time initialization */
2441 if (init_done == COLD)
2442 sc_get_bios_values(&bios_value);
2446 * Allocate resources. Even if we are being called for the second
2447 * time, we must allocate them again, because they might have
2450 sc = sc_get_softc(unit, flags & SC_KERNEL_CONSOLE);
2452 if (sc->adapter >= 0) {
2453 vid_release(sc->adp, (void *)&sc->adapter);
2457 if (sc->keyboard >= 0) {
2458 DPRINTF(5, ("sc%d: releasing kbd%d\n", unit, sc->keyboard));
2459 i = kbd_release(sc->kbd, (void *)&sc->keyboard);
2460 DPRINTF(5, ("sc%d: kbd_release returned %d\n", unit, i));
2461 if (sc->kbd != NULL) {
2462 DPRINTF(5, ("sc%d: kbd != NULL!, index:%d, unit:%d, flags:0x%x\n",
2463 unit, sc->kbd->kb_index, sc->kbd->kb_unit, sc->kbd->kb_flags));
2467 sc->adapter = vid_allocate("*", unit, (void *)&sc->adapter);
2468 sc->adp = vid_get_adapter(sc->adapter);
2469 /* assert((sc->adapter >= 0) && (sc->adp != NULL)) */
2470 sc->keyboard = kbd_allocate("*", unit, (void *)&sc->keyboard,
2472 DPRINTF(1, ("sc%d: keyboard %d\n", unit, sc->keyboard));
2473 sc->kbd = kbd_get_keyboard(sc->keyboard);
2474 if (sc->kbd != NULL) {
2475 DPRINTF(1, ("sc%d: kbd index:%d, unit:%d, flags:0x%x\n",
2476 unit, sc->kbd->kb_index, sc->kbd->kb_unit, sc->kbd->kb_flags));
2479 if (!(sc->flags & SC_INIT_DONE) || (adp != sc->adp)) {
2481 sc->initial_mode = sc->adp->va_initial_mode;
2483 #ifndef SC_NO_FONT_LOADING
2484 if (flags & SC_KERNEL_CONSOLE) {
2485 sc->font_8 = font_8;
2486 sc->font_14 = font_14;
2487 sc->font_16 = font_16;
2488 } else if (sc->font_8 == NULL) {
2489 /* assert(sc_malloc) */
2490 sc->font_8 = malloc(sizeof(font_8), M_SYSCONS, M_WAITOK);
2491 sc->font_14 = malloc(sizeof(font_14), M_SYSCONS, M_WAITOK);
2492 sc->font_16 = malloc(sizeof(font_16), M_SYSCONS, M_WAITOK);
2496 /* extract the hardware cursor location and hide the cursor for now */
2497 (*vidsw[sc->adapter]->read_hw_cursor)(sc->adp, &col, &row);
2498 (*vidsw[sc->adapter]->set_hw_cursor)(sc->adp, -1, -1);
2500 /* set up the first console */
2501 sc->first_vty = unit*MAXCONS;
2502 sc->vtys = MAXCONS; /* XXX: should be configurable */
2503 if (flags & SC_KERNEL_CONSOLE) {
2504 sc->dev = main_devs;
2505 sc->dev[0] = make_dev(&sc_cdevsw, unit*MAXCONS, UID_ROOT,
2506 GID_WHEEL, 0600, "ttyv%r", unit*MAXCONS);
2507 sc->dev[0]->si_tty = &main_tty;
2508 ttyregister(&main_tty);
2509 scp = &main_console;
2510 init_scp(sc, sc->first_vty, scp);
2511 sc_vtb_init(&scp->vtb, VTB_MEMORY, scp->xsize, scp->ysize,
2512 (void *)sc_buffer, FALSE);
2513 if (sc_init_emulator(scp, SC_DFLT_TERM))
2514 sc_init_emulator(scp, "*");
2515 (*scp->tsw->te_default_attr)(scp,
2516 kernel_default.std_color,
2517 kernel_default.rev_color);
2519 /* assert(sc_malloc) */
2520 sc->dev = malloc(sizeof(dev_t)*sc->vtys, M_SYSCONS, M_WAITOK | M_ZERO);
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_SYSCONS);
2650 /* clear the structure */
2651 if (!(flags & SC_KERNEL_CONSOLE)) {
2652 /* XXX: We need delete_dev() for this */
2653 free(sc->dev, M_SYSCONS);
2655 /* XXX: We need a ttyunregister for this */
2656 free(sc->tty, M_SYSCONS);
2658 #ifndef SC_NO_FONT_LOADING
2659 free(sc->font_8, M_SYSCONS);
2660 free(sc->font_14, M_SYSCONS);
2661 free(sc->font_16, M_SYSCONS);
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 = malloc(sizeof(scr_stat), M_SYSCONS, 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_SYSCONS, 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_SYSCONS);
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);