2 * Copyright (c) 1992-1998 Søren Schmidt
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer,
10 * without modification, immediately at the beginning of the file.
11 * 2. Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in the
13 * documentation and/or other materials provided with the distribution.
14 * 3. The name of the author may not be used to endorse or promote products
15 * derived from this software without specific prior written permission.
17 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
18 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
19 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
20 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
21 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
22 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
26 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28 * $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 $
29 * $DragonFly: src/sys/dev/misc/syscons/syscons.c,v 1.11 2004/05/19 22:52:44 dillon Exp $
32 #include "use_splash.h"
33 #include "opt_syscons.h"
39 #include <sys/param.h>
40 #include <sys/systm.h>
41 #include <sys/eventhandler.h>
42 #include <sys/reboot.h>
45 #include <sys/signalvar.h>
46 #include <sys/sysctl.h>
48 #include <sys/kernel.h>
49 #include <sys/malloc.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>
58 #include <machine/apm_bios.h>
59 #include <machine/frame.h>
62 #include <dev/misc/kbd/kbdreg.h>
63 #include <dev/video/fb/fbreg.h>
64 #include <dev/video/fb/splashreg.h>
70 #define DEFAULT_BLANKTIME (5*60) /* 5 minutes */
71 #define MAX_BLANKTIME (7*24*60*60) /* 7 days!? */
73 #define KEYCODE_BS 0x0e /* "<-- Backspace" key, XXX */
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);
140 static void scterm(int unit, int flags);
142 static void scshutdown(void *arg, int howto);
143 static u_int scgetc(sc_softc_t *sc, u_int flags);
145 #define SCGETC_NONBLOCK 2
146 static int sccngetch(int flags);
147 static void sccnupdate(scr_stat *scp);
148 static scr_stat *alloc_scp(sc_softc_t *sc, int vty);
149 static void init_scp(sc_softc_t *sc, int vty, scr_stat *scp);
150 static timeout_t scrn_timer;
151 static int and_region(int *s1, int *e1, int s2, int e2);
152 static void scrn_update(scr_stat *scp, int show_cursor);
155 static int scsplash_callback(int event, void *arg);
156 static void scsplash_saver(sc_softc_t *sc, int show);
157 static int add_scrn_saver(void (*this_saver)(sc_softc_t *, int));
158 static int remove_scrn_saver(void (*this_saver)(sc_softc_t *, int));
159 static int set_scrn_saver_mode(scr_stat *scp, int mode, u_char *pal, int border);
160 static int restore_scrn_saver_mode(scr_stat *scp, int changemode);
161 static void stop_scrn_saver(sc_softc_t *sc, void (*saver)(sc_softc_t *, int));
162 static int wait_scrn_saver_stop(sc_softc_t *sc);
163 #define scsplash_stick(stick) (sticky_splash = (stick))
165 #define scsplash_stick(stick)
168 static int do_switch_scr(sc_softc_t *sc, int s);
169 static int vt_proc_alive(scr_stat *scp);
170 static int signal_vt_rel(scr_stat *scp);
171 static int signal_vt_acq(scr_stat *scp);
172 static int finish_vt_rel(scr_stat *scp, int release, int *s);
173 static int finish_vt_acq(scr_stat *scp);
174 static void exchange_scr(sc_softc_t *sc);
175 static void update_cursor_image(scr_stat *scp);
176 static int save_kbd_state(scr_stat *scp);
177 static int update_kbd_state(scr_stat *scp, int state, int mask);
178 static int update_kbd_leds(scr_stat *scp, int which);
179 static timeout_t blink_screen;
181 #define CDEV_MAJOR 12
183 static cn_probe_t sccnprobe;
184 static cn_init_t sccninit;
185 static cn_getc_t sccngetc;
186 static cn_checkc_t sccncheckc;
187 static cn_putc_t sccnputc;
188 static cn_dbctl_t sccndbctl;
189 static cn_term_t sccnterm;
192 void sccnattach(void);
195 CONS_DRIVER(sc, sccnprobe, sccninit, sccnterm, sccngetc, sccncheckc, sccnputc,
198 static d_open_t scopen;
199 static d_close_t scclose;
200 static d_read_t scread;
201 static d_ioctl_t scioctl;
202 static d_mmap_t scmmap;
204 static struct cdevsw sc_cdevsw = {
206 /* maj */ CDEV_MAJOR,
207 /* flags */ D_TTY | D_KQFILTER,
214 /* write */ ttywrite,
218 /* strategy */ nostrategy,
221 /* kqfilter */ ttykqfilter
225 sc_probe_unit(int unit, int flags)
227 if (!scvidprobe(unit, flags, FALSE)) {
229 printf("sc%d: no video adapter found.\n", unit);
233 /* syscons will be attached even when there is no keyboard */
234 sckbdprobe(unit, flags, FALSE);
239 /* probe video adapters, return TRUE if found */
241 scvidprobe(int unit, int flags, int cons)
244 * Access the video adapter driver through the back door!
245 * Video adapter drivers need to be configured before syscons.
246 * However, when syscons is being probed as the low-level console,
247 * they have not been initialized yet. We force them to initialize
248 * themselves here. XXX
250 vid_configure(cons ? VIO_PROBE_ONLY : 0);
252 return (vid_find_adapter("*", unit) >= 0);
255 /* probe the keyboard, return TRUE if found */
257 sckbdprobe(int unit, int flags, int cons)
259 /* access the keyboard driver through the backdoor! */
260 kbd_configure(cons ? KB_CONF_PROBE_ONLY : 0);
262 return (kbd_find_keyboard("*", unit) >= 0);
266 *adapter_name(video_adapter_t *adp)
272 { KD_MONO, { "MDA", "MDA" } },
273 { KD_HERCULES, { "Hercules", "Hercules" } },
274 { KD_CGA, { "CGA", "CGA" } },
275 { KD_EGA, { "EGA", "EGA (mono)" } },
276 { KD_VGA, { "VGA", "VGA (mono)" } },
277 { KD_PC98, { "PC-98x1", "PC-98x1" } },
278 { KD_TGA, { "TGA", "TGA" } },
279 { -1, { "Unknown", "Unknown" } },
283 for (i = 0; names[i].type != -1; ++i)
284 if (names[i].type == adp->va_type)
286 return names[i].name[(adp->va_flags & V_ADP_COLOR) ? 0 : 1];
290 sc_attach_unit(int unit, int flags)
300 flags &= ~SC_KERNEL_CONSOLE;
302 if (sc_console_unit == unit) {
304 * If this unit is being used as the system console, we need to
305 * adjust some variables and buffers before and after scinit().
307 /* assert(sc_console != NULL) */
308 flags |= SC_KERNEL_CONSOLE;
313 if (sc_console->tsw->te_size > 0) {
314 /* assert(sc_console->ts != NULL); */
315 kernel_console_ts = sc_console->ts;
316 sc_console->ts = malloc(sc_console->tsw->te_size,
318 bcopy(kernel_console_ts, sc_console->ts, sc_console->tsw->te_size);
319 (*sc_console->tsw->te_default_attr)(sc_console,
320 user_default.std_color,
321 user_default.rev_color);
327 sc = sc_get_softc(unit, flags & SC_KERNEL_CONSOLE);
329 scp = SC_STAT(sc->dev[0]);
330 if (sc_console == NULL) /* sc_console_unit < 0 */
334 if ((sc->config & SC_VESA800X600)
335 && ((*vidsw[sc->adapter]->get_info)(sc->adp, M_VESA_800x600, &info) == 0)) {
337 if (sc->flags & SC_SPLASH_SCRN)
338 splash_term(sc->adp);
340 sc_set_graphics_mode(scp, NULL, M_VESA_800x600);
341 sc_set_pixel_mode(scp, NULL, COL, ROW, 16);
342 sc->initial_mode = M_VESA_800x600;
344 /* put up the splash again! */
345 if (sc->flags & SC_SPLASH_SCRN)
346 splash_init(sc->adp, scsplash_callback, sc);
349 #endif /* SC_PIXEL_MODE */
351 /* initialize cursor */
353 update_cursor_image(scp);
355 /* get screen update going */
358 /* set up the keyboard */
359 kbd_ioctl(sc->kbd, KDSKBMODE, (caddr_t)&scp->kbd_mode);
360 update_kbd_state(scp, scp->status, LOCK_MASK);
362 printf("sc%d: %s <%d virtual consoles, flags=0x%x>\n",
363 unit, adapter_name(sc->adp), sc->vtys, sc->config);
365 printf("sc%d:", unit);
366 if (sc->adapter >= 0)
367 printf(" fb%d", sc->adapter);
368 if (sc->keyboard >= 0)
369 printf(", kbd%d", sc->keyboard);
371 printf(", terminal emulator: %s (%s)",
372 scp->tsw->te_name, scp->tsw->te_desc);
376 /* register a shutdown callback for the kernel console */
377 if (sc_console_unit == unit)
378 EVENTHANDLER_REGISTER(shutdown_pre_sync, scshutdown,
379 (void *)(uintptr_t)unit, SHUTDOWN_PRI_DEFAULT);
382 * create devices. cdevsw_add() must be called to make devices under
383 * this major number available to userland.
385 cdevsw_add(&sc_cdevsw, ~(MAXCONS - 1), unit * MAXCONS);
387 for (vc = 0; vc < sc->vtys; vc++) {
388 dev = make_dev(&sc_cdevsw, vc + unit * MAXCONS,
389 UID_ROOT, GID_WHEEL, 0600, "ttyv%r", vc + unit * MAXCONS);
392 * The first vty already has struct tty and scr_stat initialized
393 * in scinit(). The other vtys will have these structs when
398 cdevsw_add(&sc_cdevsw, -1, SC_CONSOLECTL); /* XXX */
399 dev = make_dev(&sc_cdevsw, SC_CONSOLECTL,
400 UID_ROOT, GID_WHEEL, 0600, "consolectl");
401 dev->si_tty = sc_console_tty = ttymalloc(sc_console_tty);
402 SC_STAT(dev) = sc_console;
415 * As soon as malloc() becomes functional, we had better allocate
416 * various buffers for the kernel console.
419 if (sc_console_unit < 0) /* sc_console == NULL */
422 /* copy the temporary buffer to the final buffer */
423 sc_alloc_scr_buffer(sc_console, TRUE, FALSE);
425 #ifndef SC_NO_CUTPASTE
426 sc_alloc_cut_buffer(sc_console, TRUE);
429 #ifndef SC_NO_HISTORY
430 /* initialize history buffer & pointers */
431 sc_alloc_history_buffer(sc_console, 0, 0, TRUE);
436 SYSINIT(sc_mem, SI_SUB_KMEM, SI_ORDER_ANY, scmeminit, NULL);
439 scdevtounit(dev_t dev)
441 int vty = SC_VTY(dev);
443 if (vty == SC_CONSOLECTL)
444 return ((sc_console != NULL) ? sc_console->sc->unit : -1);
445 else if ((vty < 0) || (vty >= MAXCONS*sc_max_unit()))
452 scopen(dev_t dev, int flag, int mode, struct thread *td)
454 int unit = scdevtounit(dev);
461 DPRINTF(5, ("scopen: dev:%d,%d, unit:%d, vty:%d\n",
462 major(dev), minor(dev), unit, SC_VTY(dev)));
464 sc = sc_get_softc(unit, (sc_console_unit == unit) ? SC_KERNEL_CONSOLE : 0);
468 tp = dev->si_tty = ttymalloc(dev->si_tty);
469 tp->t_oproc = scstart;
470 tp->t_param = scparam;
471 tp->t_stop = nottystop;
473 if (!ISTTYOPEN(tp)) {
475 /* Use the current setting of the <-- key as default VERASE. */
476 /* If the Delete key is preferable, an stty is necessary */
477 if (sc->kbd != NULL) {
478 key.keynum = KEYCODE_BS;
479 kbd_ioctl(sc->kbd, GIO_KEYMAPENT, (caddr_t)&key);
480 tp->t_cc[VERASE] = key.key.map[0];
482 tp->t_iflag = TTYDEF_IFLAG;
483 tp->t_oflag = TTYDEF_OFLAG;
484 tp->t_cflag = TTYDEF_CFLAG;
485 tp->t_lflag = TTYDEF_LFLAG;
486 tp->t_ispeed = tp->t_ospeed = TTYDEF_SPEED;
487 scparam(tp, &tp->t_termios);
488 (*linesw[tp->t_line].l_modem)(tp, 1);
491 if (tp->t_state & TS_XCLUDE && suser(td))
494 error = (*linesw[tp->t_line].l_open)(dev, tp);
498 scp = SC_STAT(dev) = alloc_scp(sc, SC_VTY(dev));
500 sc_set_pixel_mode(scp, NULL, COL, ROW, 16);
502 if (!tp->t_winsize.ws_col && !tp->t_winsize.ws_row) {
503 tp->t_winsize.ws_col = scp->xsize;
504 tp->t_winsize.ws_row = scp->ysize;
511 scclose(dev_t dev, int flag, int mode, struct thread *td)
513 struct tty *tp = dev->si_tty;
517 if (SC_VTY(dev) != SC_CONSOLECTL) {
518 scp = SC_STAT(tp->t_dev);
519 /* were we in the middle of the VT switching process? */
520 DPRINTF(5, ("sc%d: scclose(), ", scp->sc->unit));
522 if ((scp == scp->sc->cur_scp) && (scp->sc->unit == sc_console_unit))
523 cons_unavail = FALSE;
524 if (finish_vt_rel(scp, TRUE, &s) == 0) /* force release */
525 DPRINTF(5, ("reset WAIT_REL, "));
526 if (finish_vt_acq(scp) == 0) /* force acknowledge */
527 DPRINTF(5, ("reset WAIT_ACQ, "));
529 if (scp == &main_console) {
532 scp->smode.mode = VT_AUTO;
535 sc_vtb_destroy(&scp->vtb);
536 sc_vtb_destroy(&scp->scr);
537 sc_free_history_buffer(scp, scp->ysize);
544 scp->smode.mode = VT_AUTO;
546 scp->kbd_mode = K_XLATE;
547 if (scp == scp->sc->cur_scp)
548 kbd_ioctl(scp->sc->kbd, KDSKBMODE, (caddr_t)&scp->kbd_mode);
549 DPRINTF(5, ("done.\n"));
552 (*linesw[tp->t_line].l_close)(tp, flag);
559 scread(dev_t dev, struct uio *uio, int flag)
561 sc_touch_scrn_saver();
562 return ttyread(dev, uio, flag);
566 sckbdevent(keyboard_t *thiskbd, int event, void *arg)
574 sc = (sc_softc_t *)arg;
575 /* assert(thiskbd == sc->kbd) */
580 case KBDIO_UNLOADING:
583 kbd_release(thiskbd, (void *)&sc->keyboard);
590 * Loop while there is still input to get from the keyboard.
591 * I don't think this is nessesary, and it doesn't fix
592 * the Xaccel-2.1 keyboard hang, but it can't hurt. XXX
594 while ((c = scgetc(sc, SCGETC_NONBLOCK)) != NOKEY) {
596 cur_tty = VIRTUAL_TTY(sc, sc->cur_scp->index);
597 if (!ISTTYOPEN(cur_tty)) {
598 cur_tty = sc_console_tty;
599 if (!ISTTYOPEN(cur_tty))
603 if ((*sc->cur_scp->tsw->te_input)(sc->cur_scp, c, cur_tty))
606 switch (KEYFLAGS(c)) {
607 case 0x0000: /* normal key */
608 (*linesw[cur_tty->t_line].l_rint)(KEYCHAR(c), cur_tty);
610 case FKEY: /* function key, return string */
611 cp = kbd_get_fkeystr(thiskbd, KEYCHAR(c), &len);
614 (*linesw[cur_tty->t_line].l_rint)(*cp++, cur_tty);
617 case MKEY: /* meta is active, prepend ESC */
618 (*linesw[cur_tty->t_line].l_rint)(0x1b, cur_tty);
619 (*linesw[cur_tty->t_line].l_rint)(KEYCHAR(c), cur_tty);
621 case BKEY: /* backtab fixed sequence (esc [ Z) */
622 (*linesw[cur_tty->t_line].l_rint)(0x1b, cur_tty);
623 (*linesw[cur_tty->t_line].l_rint)('[', cur_tty);
624 (*linesw[cur_tty->t_line].l_rint)('Z', cur_tty);
629 sc->cur_scp->status |= MOUSE_HIDDEN;
635 scparam(struct tty *tp, struct termios *t)
637 tp->t_ispeed = t->c_ispeed;
638 tp->t_ospeed = t->c_ospeed;
639 tp->t_cflag = t->c_cflag;
644 scioctl(dev_t dev, u_long cmd, caddr_t data, int flag, struct thread *td)
652 struct proc *p = td->td_proc;
658 /* If there is a user_ioctl function call that first */
660 error = (*sc_user_ioctl)(dev, cmd, data, flag, td);
661 if (error != ENOIOCTL)
665 error = sc_vid_ioctl(tp, cmd, data, flag, td);
666 if (error != ENOIOCTL)
669 #ifndef SC_NO_HISTORY
670 error = sc_hist_ioctl(tp, cmd, data, flag, td);
671 if (error != ENOIOCTL)
675 #ifndef SC_NO_SYSMOUSE
676 error = sc_mouse_ioctl(tp, cmd, data, flag, td);
677 if (error != ENOIOCTL)
681 scp = SC_STAT(tp->t_dev);
682 /* assert(scp != NULL) */
683 /* scp is sc_console, if SC_VTY(dev) == SC_CONSOLECTL. */
687 error = (*scp->tsw->te_ioctl)(scp, tp, cmd, data, flag, td);
688 if (error != ENOIOCTL)
692 switch (cmd) { /* process console hardware related ioctl's */
694 case GIO_ATTR: /* get current attributes */
695 /* this ioctl is not processed here, but in the terminal emulator */
698 case GIO_COLOR: /* is this a color console ? */
699 *(int *)data = (sc->adp->va_flags & V_ADP_COLOR) ? 1 : 0;
702 case CONS_BLANKTIME: /* set screen saver timeout (0 = no saver) */
703 if (*(int *)data < 0 || *(int *)data > MAX_BLANKTIME)
706 scrn_blank_time = *(int *)data;
707 run_scrn_saver = (scrn_blank_time != 0);
711 case CONS_CURSORTYPE: /* set cursor type blink/noblink */
713 if (!ISGRAPHSC(sc->cur_scp))
714 sc_remove_cursor_image(sc->cur_scp);
715 if ((*(int*)data) & 0x01)
716 sc->flags |= SC_BLINK_CURSOR;
718 sc->flags &= ~SC_BLINK_CURSOR;
719 if ((*(int*)data) & 0x02) {
720 sc->flags |= SC_CHAR_CURSOR;
722 sc->flags &= ~SC_CHAR_CURSOR;
724 * The cursor shape is global property; all virtual consoles
725 * are affected. Update the cursor in the current console...
727 if (!ISGRAPHSC(sc->cur_scp)) {
728 sc_set_cursor_image(sc->cur_scp);
729 sc_draw_cursor_image(sc->cur_scp);
734 case CONS_BELLTYPE: /* set bell type sound/visual */
735 if ((*(int *)data) & 0x01)
736 sc->flags |= SC_VISUAL_BELL;
738 sc->flags &= ~SC_VISUAL_BELL;
739 if ((*(int *)data) & 0x02)
740 sc->flags |= SC_QUIET_BELL;
742 sc->flags &= ~SC_QUIET_BELL;
745 case CONS_GETINFO: /* get current (virtual) console info */
747 vid_info_t *ptr = (vid_info_t*)data;
748 if (ptr->size == sizeof(struct vid_info)) {
749 ptr->m_num = sc->cur_scp->index;
750 ptr->font_size = scp->font_size;
751 ptr->mv_col = scp->xpos;
752 ptr->mv_row = scp->ypos;
753 ptr->mv_csz = scp->xsize;
754 ptr->mv_rsz = scp->ysize;
756 * The following fields are filled by the terminal emulator. XXX
763 ptr->mv_grfc.fore = 0; /* not supported */
764 ptr->mv_grfc.back = 0; /* not supported */
765 ptr->mv_ovscan = scp->border;
766 if (scp == sc->cur_scp)
768 ptr->mk_keylock = scp->status & LOCK_MASK;
774 case CONS_GETVERS: /* get version number */
775 *(int*)data = 0x200; /* version 2.0 */
778 case CONS_IDLE: /* see if the screen has been idle */
780 * When the screen is in the GRAPHICS_MODE or UNKNOWN_MODE,
781 * the user process may have been writing something on the
782 * screen and syscons is not aware of it. Declare the screen
783 * is NOT idle if it is in one of these modes. But there is
784 * an exception to it; if a screen saver is running in the
785 * graphics mode in the current screen, we should say that the
786 * screen has been idle.
788 *(int *)data = (sc->flags & SC_SCRN_IDLE)
789 && (!ISGRAPHSC(sc->cur_scp)
790 || (sc->cur_scp->status & SAVER_RUNNING));
793 case CONS_SAVERMODE: /* set saver mode */
794 switch(*(int *)data) {
797 /* if a LKM screen saver is running, stop it first. */
798 scsplash_stick(FALSE);
799 saver_mode = *(int *)data;
802 if ((error = wait_scrn_saver_stop(NULL))) {
807 run_scrn_saver = TRUE;
808 if (saver_mode == CONS_USR_SAVER)
809 scp->status |= SAVER_RUNNING;
811 scp->status &= ~SAVER_RUNNING;
812 scsplash_stick(TRUE);
817 if ((saver_mode == CONS_USR_SAVER) && (scp->status & SAVER_RUNNING))
818 scp->status &= ~SAVER_RUNNING;
819 saver_mode = *(int *)data;
827 case CONS_SAVERSTART: /* immediately start/stop the screen saver */
829 * Note that this ioctl does not guarantee the screen saver
830 * actually starts or stops. It merely attempts to do so...
833 run_scrn_saver = (*(int *)data != 0);
835 sc->scrn_time_stamp -= scrn_blank_time;
839 case CONS_SCRSHOT: /* get a screen shot */
841 scrshot_t *ptr = (scrshot_t*)data;
843 if (ISGRAPHSC(scp)) {
847 if (scp->xsize != ptr->xsize || scp->ysize != ptr->ysize) {
851 copyout ((void*)scp->vtb.vtb_buffer, ptr->buf,
852 ptr->xsize * ptr->ysize * sizeof(u_int16_t));
857 case VT_SETMODE: /* set screen switcher mode */
859 struct vt_mode *mode;
861 mode = (struct vt_mode *)data;
862 DPRINTF(5, ("sc%d: VT_SETMODE ", sc->unit));
863 if (scp->smode.mode == VT_PROCESS) {
864 if (scp->proc == pfind(scp->pid) && scp->proc != p) {
865 DPRINTF(5, ("error EPERM\n"));
870 if (mode->mode == VT_AUTO) {
871 scp->smode.mode = VT_AUTO;
874 DPRINTF(5, ("VT_AUTO, "));
875 if ((scp == sc->cur_scp) && (sc->unit == sc_console_unit))
876 cons_unavail = FALSE;
877 /* were we in the middle of the vty switching process? */
878 if (finish_vt_rel(scp, TRUE, &s) == 0)
879 DPRINTF(5, ("reset WAIT_REL, "));
880 if (finish_vt_acq(scp) == 0)
881 DPRINTF(5, ("reset WAIT_ACQ, "));
883 if (!ISSIGVALID(mode->relsig) || !ISSIGVALID(mode->acqsig)
884 || !ISSIGVALID(mode->frsig)) {
886 DPRINTF(5, ("error EINVAL\n"));
889 DPRINTF(5, ("VT_PROCESS %d, ", p->p_pid));
890 bcopy(data, &scp->smode, sizeof(struct vt_mode));
892 scp->pid = scp->proc->p_pid;
893 if ((scp == sc->cur_scp) && (sc->unit == sc_console_unit))
901 case VT_GETMODE: /* get screen switcher mode */
902 bcopy(&scp->smode, data, sizeof(struct vt_mode));
905 case VT_RELDISP: /* screen switcher ioctl */
908 * This must be the current vty which is in the VT_PROCESS
911 if ((scp != sc->cur_scp) || (scp->smode.mode != VT_PROCESS)) {
915 /* ...and this process is controlling it. */
916 if (scp->proc != p) {
921 switch(*(int *)data) {
922 case VT_FALSE: /* user refuses to release screen, abort */
923 if ((error = finish_vt_rel(scp, FALSE, &s)) == 0)
924 DPRINTF(5, ("sc%d: VT_FALSE\n", sc->unit));
926 case VT_TRUE: /* user has released screen, go on */
927 if ((error = finish_vt_rel(scp, TRUE, &s)) == 0)
928 DPRINTF(5, ("sc%d: VT_TRUE\n", sc->unit));
930 case VT_ACKACQ: /* acquire acknowledged, switch completed */
931 if ((error = finish_vt_acq(scp)) == 0)
932 DPRINTF(5, ("sc%d: VT_ACKACQ\n", sc->unit));
940 case VT_OPENQRY: /* return free virtual console */
941 for (i = sc->first_vty; i < sc->first_vty + sc->vtys; i++) {
942 tp = VIRTUAL_TTY(sc, i);
943 if (!ISTTYOPEN(tp)) {
944 *(int *)data = i + 1;
950 case VT_ACTIVATE: /* switch to screen *data */
951 i = (*(int *)data == 0) ? scp->index : (*(int *)data - 1);
953 sc_clean_up(sc->cur_scp);
955 return sc_switch_scr(sc, i);
957 case VT_WAITACTIVE: /* wait for switch to occur */
958 i = (*(int *)data == 0) ? scp->index : (*(int *)data - 1);
959 if ((i < sc->first_vty) || (i >= sc->first_vty + sc->vtys))
962 error = sc_clean_up(sc->cur_scp);
966 scp = SC_STAT(SC_DEV(sc, i));
967 if (scp == scp->sc->cur_scp)
969 while ((error=tsleep((caddr_t)&scp->smode, PCATCH,
970 "waitvt", 0)) == ERESTART) ;
973 case VT_GETACTIVE: /* get active vty # */
974 *(int *)data = sc->cur_scp->index + 1;
977 case VT_GETINDEX: /* get this vty # */
978 *(int *)data = scp->index + 1;
981 case VT_LOCKSWITCH: /* prevent vty switching */
982 if ((*(int *)data) & 0x01)
983 sc->flags |= SC_SCRN_VTYLOCK;
985 sc->flags &= ~SC_SCRN_VTYLOCK;
988 case KDENABIO: /* allow io operations */
995 p->p_md.md_regs->tf_eflags |= PSL_IOPL;
999 case KDDISABIO: /* disallow io operations (default) */
1001 p->p_md.md_regs->tf_eflags &= ~PSL_IOPL;
1005 case KDSKBSTATE: /* set keyboard state (locks) */
1006 if (*(int *)data & ~LOCK_MASK)
1008 scp->status &= ~LOCK_MASK;
1009 scp->status |= *(int *)data;
1010 if (scp == sc->cur_scp)
1011 update_kbd_state(scp, scp->status, LOCK_MASK);
1014 case KDGKBSTATE: /* get keyboard state (locks) */
1015 if (scp == sc->cur_scp)
1016 save_kbd_state(scp);
1017 *(int *)data = scp->status & LOCK_MASK;
1020 case KDGETREPEAT: /* get keyboard repeat & delay rates */
1021 case KDSETREPEAT: /* set keyboard repeat & delay rates (new) */
1022 error = kbd_ioctl(sc->kbd, cmd, data);
1023 if (error == ENOIOCTL)
1027 case KDSETRAD: /* set keyboard repeat & delay rates (old) */
1028 if (*(int *)data & ~0x7f)
1030 error = kbd_ioctl(sc->kbd, cmd, data);
1031 if (error == ENOIOCTL)
1035 case KDSKBMODE: /* set keyboard mode */
1036 switch (*(int *)data) {
1037 case K_XLATE: /* switch to XLT ascii mode */
1038 case K_RAW: /* switch to RAW scancode mode */
1039 case K_CODE: /* switch to CODE mode */
1040 scp->kbd_mode = *(int *)data;
1041 if (scp == sc->cur_scp)
1042 kbd_ioctl(sc->kbd, cmd, data);
1049 case KDGKBMODE: /* get keyboard mode */
1050 *(int *)data = scp->kbd_mode;
1054 error = kbd_ioctl(sc->kbd, cmd, data);
1055 if (error == ENOIOCTL)
1059 case KDMKTONE: /* sound the bell */
1061 sc_bell(scp, (*(int*)data)&0xffff,
1062 (((*(int*)data)>>16)&0xffff)*hz/1000);
1064 sc_bell(scp, scp->bell_pitch, scp->bell_duration);
1067 case KIOCSOUND: /* make tone (*data) hz */
1068 if (scp == sc->cur_scp) {
1070 return sc_tone(*(int *)data);
1076 case KDGKBTYPE: /* get keyboard type */
1077 error = kbd_ioctl(sc->kbd, cmd, data);
1078 if (error == ENOIOCTL) {
1079 /* always return something? XXX */
1084 case KDSETLED: /* set keyboard LED status */
1085 if (*(int *)data & ~LED_MASK) /* FIXME: LOCK_MASK? */
1087 scp->status &= ~LED_MASK;
1088 scp->status |= *(int *)data;
1089 if (scp == sc->cur_scp)
1090 update_kbd_leds(scp, scp->status);
1093 case KDGETLED: /* get keyboard LED status */
1094 if (scp == sc->cur_scp)
1095 save_kbd_state(scp);
1096 *(int *)data = scp->status & LED_MASK;
1099 case CONS_SETKBD: /* set the new keyboard */
1104 newkbd = kbd_get_keyboard(*(int *)data);
1105 if (newkbd == NULL) {
1110 if (sc->kbd != newkbd) {
1111 i = kbd_allocate(newkbd->kb_name, newkbd->kb_unit,
1112 (void *)&sc->keyboard, sckbdevent, sc);
1113 /* i == newkbd->kb_index */
1115 if (sc->kbd != NULL) {
1116 save_kbd_state(sc->cur_scp);
1117 kbd_release(sc->kbd, (void *)&sc->keyboard);
1119 sc->kbd = kbd_get_keyboard(i); /* sc->kbd == newkbd */
1121 kbd_ioctl(sc->kbd, KDSKBMODE,
1122 (caddr_t)&sc->cur_scp->kbd_mode);
1123 update_kbd_state(sc->cur_scp, sc->cur_scp->status,
1126 error = EPERM; /* XXX */
1133 case CONS_RELKBD: /* release the current keyboard */
1136 if (sc->kbd != NULL) {
1137 save_kbd_state(sc->cur_scp);
1138 error = kbd_release(sc->kbd, (void *)&sc->keyboard);
1147 case CONS_GETTERM: /* get the current terminal emulator info */
1151 if (((term_info_t *)data)->ti_index == 0) {
1154 sw = sc_term_match_by_number(((term_info_t *)data)->ti_index);
1157 strncpy(((term_info_t *)data)->ti_name, sw->te_name,
1158 sizeof(((term_info_t *)data)->ti_name));
1159 strncpy(((term_info_t *)data)->ti_desc, sw->te_desc,
1160 sizeof(((term_info_t *)data)->ti_desc));
1161 ((term_info_t *)data)->ti_flags = 0;
1164 ((term_info_t *)data)->ti_name[0] = '\0';
1165 ((term_info_t *)data)->ti_desc[0] = '\0';
1166 ((term_info_t *)data)->ti_flags = 0;
1171 case CONS_SETTERM: /* set the current terminal emulator */
1173 error = sc_init_emulator(scp, ((term_info_t *)data)->ti_name);
1174 /* FIXME: what if scp == sc_console! XXX */
1178 case GIO_SCRNMAP: /* get output translation table */
1179 bcopy(&sc->scr_map, data, sizeof(sc->scr_map));
1182 case PIO_SCRNMAP: /* set output translation table */
1183 bcopy(data, &sc->scr_map, sizeof(sc->scr_map));
1184 for (i=0; i<sizeof(sc->scr_map); i++) {
1185 sc->scr_rmap[sc->scr_map[i]] = i;
1189 case GIO_KEYMAP: /* get keyboard translation table */
1190 case PIO_KEYMAP: /* set keyboard translation table */
1191 case GIO_DEADKEYMAP: /* get accent key translation table */
1192 case PIO_DEADKEYMAP: /* set accent key translation table */
1193 case GETFKEY: /* get function key string */
1194 case SETFKEY: /* set function key string */
1195 error = kbd_ioctl(sc->kbd, cmd, data);
1196 if (error == ENOIOCTL)
1200 #ifndef SC_NO_FONT_LOADING
1202 case PIO_FONT8x8: /* set 8x8 dot font */
1203 if (!ISFONTAVAIL(sc->adp->va_flags))
1205 bcopy(data, sc->font_8, 8*256);
1206 sc->fonts_loaded |= FONT_8;
1209 * Always use the font page #0. XXX
1210 * Don't load if the current font size is not 8x8.
1212 if (ISTEXTSC(sc->cur_scp) && (sc->cur_scp->font_size < 14))
1213 sc_load_font(sc->cur_scp, 0, 8, sc->font_8, 0, 256);
1216 case GIO_FONT8x8: /* get 8x8 dot font */
1217 if (!ISFONTAVAIL(sc->adp->va_flags))
1219 if (sc->fonts_loaded & FONT_8) {
1220 bcopy(sc->font_8, data, 8*256);
1226 case PIO_FONT8x14: /* set 8x14 dot font */
1227 if (!ISFONTAVAIL(sc->adp->va_flags))
1229 bcopy(data, sc->font_14, 14*256);
1230 sc->fonts_loaded |= FONT_14;
1233 * Always use the font page #0. XXX
1234 * Don't load if the current font size is not 8x14.
1236 if (ISTEXTSC(sc->cur_scp)
1237 && (sc->cur_scp->font_size >= 14)
1238 && (sc->cur_scp->font_size < 16))
1239 sc_load_font(sc->cur_scp, 0, 14, sc->font_14, 0, 256);
1242 case GIO_FONT8x14: /* get 8x14 dot font */
1243 if (!ISFONTAVAIL(sc->adp->va_flags))
1245 if (sc->fonts_loaded & FONT_14) {
1246 bcopy(sc->font_14, data, 14*256);
1252 case PIO_FONT8x16: /* set 8x16 dot font */
1253 if (!ISFONTAVAIL(sc->adp->va_flags))
1255 bcopy(data, sc->font_16, 16*256);
1256 sc->fonts_loaded |= FONT_16;
1259 * Always use the font page #0. XXX
1260 * Don't load if the current font size is not 8x16.
1262 if (ISTEXTSC(sc->cur_scp) && (sc->cur_scp->font_size >= 16))
1263 sc_load_font(sc->cur_scp, 0, 16, sc->font_16, 0, 256);
1266 case GIO_FONT8x16: /* get 8x16 dot font */
1267 if (!ISFONTAVAIL(sc->adp->va_flags))
1269 if (sc->fonts_loaded & FONT_16) {
1270 bcopy(sc->font_16, data, 16*256);
1276 #endif /* SC_NO_FONT_LOADING */
1282 error = (*linesw[tp->t_line].l_ioctl)(tp, cmd, data, flag, td);
1283 if (error != ENOIOCTL)
1285 error = ttioctl(tp, cmd, data, flag);
1286 if (error != ENOIOCTL)
1292 scstart(struct tty *tp)
1296 u_char buf[PCBURST];
1297 scr_stat *scp = SC_STAT(tp->t_dev);
1299 if (scp->status & SLKED ||
1300 (scp == scp->sc->cur_scp && scp->sc->blink_in_progress))
1303 if (!(tp->t_state & (TS_TIMEOUT | TS_BUSY | TS_TTSTOP))) {
1304 tp->t_state |= TS_BUSY;
1307 len = q_to_b(rbp, buf, PCBURST);
1309 sc_puts(scp, buf, len);
1312 tp->t_state &= ~TS_BUSY;
1319 sccnprobe(struct consdev *cp)
1325 cp->cn_pri = sc_get_cons_priority(&unit, &flags);
1327 /* a video card is always required */
1328 if (!scvidprobe(unit, flags, TRUE))
1329 cp->cn_pri = CN_DEAD;
1331 /* syscons will become console even when there is no keyboard */
1332 sckbdprobe(unit, flags, TRUE);
1334 if (cp->cn_pri == CN_DEAD)
1337 /* initialize required fields */
1338 cp->cn_dev = make_dev(&sc_cdevsw, SC_CONSOLECTL,
1339 UID_ROOT, GID_WHEEL, 0600, "consolectl");
1340 #endif /* __i386__ */
1344 * alpha use sccnattach() rather than cnprobe()/cninit()/cnterm()
1345 * interface to install the console. Always return CN_DEAD from
1348 cp->cn_pri = CN_DEAD;
1349 #endif /* __alpha__ */
1353 sccninit(struct consdev *cp)
1359 sc_get_cons_priority(&unit, &flags);
1360 scinit(unit, flags | SC_KERNEL_CONSOLE);
1361 sc_console_unit = unit;
1362 sc_console = SC_STAT(sc_get_softc(unit, SC_KERNEL_CONSOLE)->dev[0]);
1363 #endif /* __i386__ */
1366 /* SHOULDN'T REACH HERE */
1367 #endif /* __alpha__ */
1371 sccnterm(struct consdev *cp)
1373 /* we are not the kernel console any more, release everything */
1375 if (sc_console_unit < 0)
1376 return; /* shouldn't happen */
1380 sc_clear_screen(sc_console);
1381 sccnupdate(sc_console);
1383 scterm(sc_console_unit, SC_KERNEL_CONSOLE);
1384 sc_console_unit = -1;
1386 #endif /* __i386__ */
1389 /* do nothing XXX */
1390 #endif /* __alpha__ */
1398 static struct consdev consdev;
1402 bcopy(&sc_consdev, &consdev, sizeof(sc_consdev));
1403 consdev.cn_pri = sc_get_cons_priority(&unit, &flags);
1405 /* a video card is always required */
1406 if (!scvidprobe(unit, flags, TRUE))
1407 consdev.cn_pri = CN_DEAD;
1409 /* alpha doesn't allow the console being without a keyboard... Why? */
1410 if (!sckbdprobe(unit, flags, TRUE))
1411 consdev.cn_pri = CN_DEAD;
1413 if (consdev.cn_pri == CN_DEAD)
1416 scinit(unit, flags | SC_KERNEL_CONSOLE);
1417 sc_console_unit = unit;
1418 sc_console = SC_STAT(sc_get_softc(unit, SC_KERNEL_CONSOLE)->dev[0]);
1419 consdev.cn_dev = make_dev(&sc_cdevsw, 0, UID_ROOT, GID_WHEEL, 0600,
1424 #endif /* __alpha__ */
1427 sccnputc(dev_t dev, int c)
1430 scr_stat *scp = sc_console;
1432 #ifndef SC_NO_HISTORY
1434 #endif /* !SC_NO_HISTORY */
1437 /* assert(sc_console != NULL) */
1439 #ifndef SC_NO_HISTORY
1440 if (scp == scp->sc->cur_scp && scp->status & SLKED) {
1441 scp->status &= ~SLKED;
1442 update_kbd_state(scp, scp->status, SLKED);
1443 if (scp->status & BUFFER_SAVED) {
1444 if (!sc_hist_restore(scp))
1445 sc_remove_cutmarking(scp);
1446 scp->status &= ~BUFFER_SAVED;
1447 scp->status |= CURSOR_ENABLED;
1448 sc_draw_cursor_image(scp);
1450 tp = VIRTUAL_TTY(scp->sc, scp->index);
1454 #endif /* !SC_NO_HISTORY */
1457 if (kernel_console_ts != NULL)
1458 scp->ts = kernel_console_ts;
1460 sc_puts(scp, buf, 1);
1463 s = spltty(); /* block sckbdevent and scrn_timer */
1471 return sccngetch(0);
1475 sccncheckc(dev_t dev)
1477 return sccngetch(SCGETC_NONBLOCK);
1481 sccndbctl(dev_t dev, int on)
1483 /* assert(sc_console_unit >= 0) */
1484 /* try to switch to the kernel console screen */
1485 if (on && debugger == 0) {
1487 * TRY to make sure the screen saver is stopped,
1488 * and the screen is updated before switching to
1493 && sc_console->sc->cur_scp->smode.mode == VT_AUTO
1494 && sc_console->smode.mode == VT_AUTO) {
1495 sc_console->sc->cur_scp->status |= MOUSE_HIDDEN;
1496 sc_switch_scr(sc_console->sc, sc_console->index);
1506 sccngetch(int flags)
1508 static struct fkeytab fkey;
1513 int s = spltty(); /* block sckbdevent and scrn_timer while we poll */
1516 /* assert(sc_console != NULL) */
1519 * Stop the screen saver and update the screen if necessary.
1520 * What if we have been running in the screen saver code... XXX
1522 sc_touch_scrn_saver();
1523 scp = sc_console->sc->cur_scp; /* XXX */
1526 if (fkeycp < fkey.len) {
1528 return fkey.str[fkeycp++];
1531 if (scp->sc->kbd == NULL) {
1537 * Make sure the keyboard is accessible even when the kbd device
1538 * driver is disabled.
1540 kbd_enable(scp->sc->kbd);
1542 /* we shall always use the keyboard in the XLATE mode here */
1543 cur_mode = scp->kbd_mode;
1544 scp->kbd_mode = K_XLATE;
1545 kbd_ioctl(scp->sc->kbd, KDSKBMODE, (caddr_t)&scp->kbd_mode);
1547 kbd_poll(scp->sc->kbd, TRUE);
1548 c = scgetc(scp->sc, SCGETC_CN | flags);
1549 kbd_poll(scp->sc->kbd, FALSE);
1551 scp->kbd_mode = cur_mode;
1552 kbd_ioctl(scp->sc->kbd, KDSKBMODE, (caddr_t)&scp->kbd_mode);
1553 kbd_disable(scp->sc->kbd);
1556 switch (KEYFLAGS(c)) {
1557 case 0: /* normal char */
1559 case FKEY: /* function key */
1560 p = kbd_get_fkeystr(scp->sc->kbd, KEYCHAR(c), (size_t *)&fkeycp);
1562 if ((p != NULL) && (fkey.len > 0)) {
1563 bcopy(p, fkey.str, fkey.len);
1577 sccnupdate(scr_stat *scp)
1579 /* this is a cut-down version of scrn_timer()... */
1581 if (scp->sc->font_loading_in_progress || scp->sc->videoio_in_progress)
1584 if (debugger > 0 || panicstr || shutdown_in_progress) {
1585 sc_touch_scrn_saver();
1586 } else if (scp != scp->sc->cur_scp) {
1590 if (!run_scrn_saver)
1591 scp->sc->flags &= ~SC_SCRN_IDLE;
1593 if ((saver_mode != CONS_LKM_SAVER) || !(scp->sc->flags & SC_SCRN_IDLE))
1594 if (scp->sc->flags & SC_SCRN_BLANKED)
1595 stop_scrn_saver(scp->sc, current_saver);
1596 #endif /* NSPLASH */
1598 if (scp != scp->sc->cur_scp || scp->sc->blink_in_progress
1599 || scp->sc->switch_in_progress)
1602 * FIXME: unlike scrn_timer(), we call scrn_update() from here even
1603 * when write_in_progress is non-zero. XXX
1606 if (!ISGRAPHSC(scp) && !(scp->sc->flags & SC_SCRN_BLANKED))
1607 scrn_update(scp, TRUE);
1611 scrn_timer(void *arg)
1613 static int kbd_interval = 0;
1620 again = (arg != NULL);
1622 sc = (sc_softc_t *)arg;
1623 else if (sc_console != NULL)
1624 sc = sc_console->sc;
1628 /* don't do anything when we are performing some I/O operations */
1629 if (sc->font_loading_in_progress || sc->videoio_in_progress) {
1631 timeout(scrn_timer, sc, hz / 10);
1636 if ((sc->kbd == NULL) && (sc->config & SC_AUTODETECT_KBD)) {
1637 /* try to allocate a keyboard automatically */
1638 if (++kbd_interval >= 25) {
1639 sc->keyboard = kbd_allocate("*", -1, (void *)&sc->keyboard,
1641 if (sc->keyboard >= 0) {
1642 sc->kbd = kbd_get_keyboard(sc->keyboard);
1643 kbd_ioctl(sc->kbd, KDSKBMODE,
1644 (caddr_t)&sc->cur_scp->kbd_mode);
1645 update_kbd_state(sc->cur_scp, sc->cur_scp->status,
1652 /* find the vty to update */
1655 /* should we stop the screen saver? */
1656 getmicrouptime(&tv);
1657 if (debugger > 0 || panicstr || shutdown_in_progress)
1658 sc_touch_scrn_saver();
1659 if (run_scrn_saver) {
1660 if (tv.tv_sec > sc->scrn_time_stamp + scrn_blank_time)
1661 sc->flags |= SC_SCRN_IDLE;
1663 sc->flags &= ~SC_SCRN_IDLE;
1665 sc->scrn_time_stamp = tv.tv_sec;
1666 sc->flags &= ~SC_SCRN_IDLE;
1667 if (scrn_blank_time > 0)
1668 run_scrn_saver = TRUE;
1671 if ((saver_mode != CONS_LKM_SAVER) || !(sc->flags & SC_SCRN_IDLE))
1672 if (sc->flags & SC_SCRN_BLANKED)
1673 stop_scrn_saver(sc, current_saver);
1674 #endif /* NSPLASH */
1676 /* should we just return ? */
1677 if (sc->blink_in_progress || sc->switch_in_progress
1678 || sc->write_in_progress) {
1680 timeout(scrn_timer, sc, hz / 10);
1685 /* Update the screen */
1686 scp = sc->cur_scp; /* cur_scp may have changed... */
1687 if (!ISGRAPHSC(scp) && !(sc->flags & SC_SCRN_BLANKED))
1688 scrn_update(scp, TRUE);
1691 /* should we activate the screen saver? */
1692 if ((saver_mode == CONS_LKM_SAVER) && (sc->flags & SC_SCRN_IDLE))
1693 if (!ISGRAPHSC(scp) || (sc->flags & SC_SCRN_BLANKED))
1694 (*current_saver)(sc, TRUE);
1695 #endif /* NSPLASH */
1698 timeout(scrn_timer, sc, hz / 25);
1703 and_region(int *s1, int *e1, int s2, int e2)
1705 if (*e1 < s2 || e2 < *s1)
1707 *s1 = imax(*s1, s2);
1708 *e1 = imin(*e1, e2);
1713 scrn_update(scr_stat *scp, int show_cursor)
1720 /* assert(scp == scp->sc->cur_scp) */
1722 ++scp->sc->videoio_in_progress;
1724 #ifndef SC_NO_CUTPASTE
1725 /* remove the previous mouse pointer image if necessary */
1726 if (scp->status & MOUSE_VISIBLE) {
1728 e = scp->mouse_pos + scp->xsize + 1;
1729 if ((scp->status & (MOUSE_MOVED | MOUSE_HIDDEN))
1730 || and_region(&s, &e, scp->start, scp->end)
1731 || ((scp->status & CURSOR_ENABLED) &&
1732 (scp->cursor_pos != scp->cursor_oldpos) &&
1733 (and_region(&s, &e, scp->cursor_pos, scp->cursor_pos)
1734 || and_region(&s, &e, scp->cursor_oldpos, scp->cursor_oldpos)))) {
1735 sc_remove_mouse_image(scp);
1736 if (scp->end >= scp->xsize*scp->ysize)
1737 scp->end = scp->xsize*scp->ysize - 1;
1740 #endif /* !SC_NO_CUTPASTE */
1744 if (scp->end >= scp->xsize*scp->ysize) {
1745 printf("scrn_update(): scp->end %d > size_of_screen!!\n", scp->end);
1746 scp->end = scp->xsize*scp->ysize - 1;
1748 if (scp->start < 0) {
1749 printf("scrn_update(): scp->start %d < 0\n", scp->start);
1754 /* update screen image */
1755 if (scp->start <= scp->end) {
1756 if (scp->mouse_cut_end >= 0) {
1757 /* there is a marked region for cut & paste */
1758 if (scp->mouse_cut_start <= scp->mouse_cut_end) {
1759 start = scp->mouse_cut_start;
1760 end = scp->mouse_cut_end;
1762 start = scp->mouse_cut_end;
1763 end = scp->mouse_cut_start - 1;
1767 /* does the cut-mark region overlap with the update region? */
1768 if (and_region(&s, &e, scp->start, scp->end)) {
1769 (*scp->rndr->draw)(scp, s, e - s + 1, TRUE);
1772 if (and_region(&s, &e, scp->start, scp->end))
1773 (*scp->rndr->draw)(scp, s, e - s + 1, FALSE);
1775 e = scp->xsize*scp->ysize - 1;
1776 if (and_region(&s, &e, scp->start, scp->end))
1777 (*scp->rndr->draw)(scp, s, e - s + 1, FALSE);
1779 (*scp->rndr->draw)(scp, scp->start,
1780 scp->end - scp->start + 1, FALSE);
1783 (*scp->rndr->draw)(scp, scp->start,
1784 scp->end - scp->start + 1, FALSE);
1788 /* we are not to show the cursor and the mouse pointer... */
1791 scp->start = scp->xsize*scp->ysize - 1;
1792 --scp->sc->videoio_in_progress;
1796 /* update cursor image */
1797 if (scp->status & CURSOR_ENABLED) {
1800 /* did cursor move since last time ? */
1801 if (scp->cursor_pos != scp->cursor_oldpos) {
1802 /* do we need to remove old cursor image ? */
1803 if (!and_region(&s, &e, scp->cursor_oldpos, scp->cursor_oldpos))
1804 sc_remove_cursor_image(scp);
1805 sc_draw_cursor_image(scp);
1807 if (and_region(&s, &e, scp->cursor_pos, scp->cursor_pos))
1808 /* cursor didn't move, but has been overwritten */
1809 sc_draw_cursor_image(scp);
1810 else if (scp->sc->flags & SC_BLINK_CURSOR)
1811 /* if it's a blinking cursor, update it */
1812 (*scp->rndr->blink_cursor)(scp, scp->cursor_pos,
1813 sc_inside_cutmark(scp,
1818 #ifndef SC_NO_CUTPASTE
1819 /* update "pseudo" mouse pointer image */
1820 if (scp->sc->flags & SC_MOUSE_ENABLED) {
1821 if (!(scp->status & (MOUSE_VISIBLE | MOUSE_HIDDEN))) {
1822 scp->status &= ~MOUSE_MOVED;
1823 sc_draw_mouse_image(scp);
1826 #endif /* SC_NO_CUTPASTE */
1829 scp->start = scp->xsize*scp->ysize - 1;
1831 --scp->sc->videoio_in_progress;
1836 scsplash_callback(int event, void *arg)
1841 sc = (sc_softc_t *)arg;
1845 if (add_scrn_saver(scsplash_saver) == 0) {
1846 sc->flags &= ~SC_SAVER_FAILED;
1847 run_scrn_saver = TRUE;
1848 if (cold && !(boothowto & (RB_VERBOSE | RB_CONFIG))) {
1849 scsplash_stick(TRUE);
1850 (*current_saver)(sc, TRUE);
1856 if (current_saver == scsplash_saver) {
1857 scsplash_stick(FALSE);
1858 error = remove_scrn_saver(scsplash_saver);
1870 scsplash_saver(sc_softc_t *sc, int show)
1872 static int busy = FALSE;
1881 if (!(sc->flags & SC_SAVER_FAILED)) {
1882 if (!(sc->flags & SC_SCRN_BLANKED))
1883 set_scrn_saver_mode(scp, -1, NULL, 0);
1884 switch (splash(sc->adp, TRUE)) {
1885 case 0: /* succeeded */
1887 case EAGAIN: /* try later */
1888 restore_scrn_saver_mode(scp, FALSE);
1889 sc_touch_scrn_saver(); /* XXX */
1892 sc->flags |= SC_SAVER_FAILED;
1893 scsplash_stick(FALSE);
1894 restore_scrn_saver_mode(scp, TRUE);
1895 printf("scsplash_saver(): failed to put up the image\n");
1899 } else if (!sticky_splash) {
1900 if ((sc->flags & SC_SCRN_BLANKED) && (splash(sc->adp, FALSE) == 0))
1901 restore_scrn_saver_mode(scp, TRUE);
1907 add_scrn_saver(void (*this_saver)(sc_softc_t *, int))
1912 if (current_saver != none_saver) {
1913 error = remove_scrn_saver(current_saver);
1918 if (current_saver != none_saver)
1921 run_scrn_saver = FALSE;
1922 saver_mode = CONS_LKM_SAVER;
1923 current_saver = this_saver;
1928 remove_scrn_saver(void (*this_saver)(sc_softc_t *, int))
1930 if (current_saver != this_saver)
1935 * In order to prevent `current_saver' from being called by
1936 * the timeout routine `scrn_timer()' while we manipulate
1937 * the saver list, we shall set `current_saver' to `none_saver'
1938 * before stopping the current saver, rather than blocking by `splXX()'.
1940 current_saver = none_saver;
1942 stop_scrn_saver(this_saver);
1945 /* unblank all blanked screens */
1946 wait_scrn_saver_stop(NULL);
1950 current_saver = none_saver;
1955 set_scrn_saver_mode(scr_stat *scp, int mode, u_char *pal, int border)
1959 /* assert(scp == scp->sc->cur_scp) */
1961 if (!ISGRAPHSC(scp))
1962 sc_remove_cursor_image(scp);
1963 scp->splash_save_mode = scp->mode;
1964 scp->splash_save_status = scp->status & (GRAPHICS_MODE | PIXEL_MODE);
1965 scp->status &= ~(GRAPHICS_MODE | PIXEL_MODE);
1966 scp->status |= (UNKNOWN_MODE | SAVER_RUNNING);
1967 scp->sc->flags |= SC_SCRN_BLANKED;
1973 if (set_mode(scp) == 0) {
1974 if (scp->sc->adp->va_info.vi_flags & V_INFO_GRAPHICS)
1975 scp->status |= GRAPHICS_MODE;
1976 #ifndef SC_NO_PALETTE_LOADING
1978 load_palette(scp->sc->adp, pal);
1980 sc_set_border(scp, border);
1984 scp->mode = scp->splash_save_mode;
1985 scp->status &= ~(UNKNOWN_MODE | SAVER_RUNNING);
1986 scp->status |= scp->splash_save_status;
1993 restore_scrn_saver_mode(scr_stat *scp, int changemode)
1999 /* assert(scp == scp->sc->cur_scp) */
2002 status = scp->status;
2003 scp->mode = scp->splash_save_mode;
2004 scp->status &= ~(UNKNOWN_MODE | SAVER_RUNNING);
2005 scp->status |= scp->splash_save_status;
2006 scp->sc->flags &= ~SC_SCRN_BLANKED;
2008 if (!ISGRAPHSC(scp))
2009 sc_draw_cursor_image(scp);
2014 if (set_mode(scp) == 0) {
2015 #ifndef SC_NO_PALETTE_LOADING
2016 load_palette(scp->sc->adp, scp->sc->palette);
2023 scp->status = status;
2030 stop_scrn_saver(sc_softc_t *sc, void (*saver)(sc_softc_t *, int))
2032 (*saver)(sc, FALSE);
2033 run_scrn_saver = FALSE;
2034 /* the screen saver may have chosen not to stop after all... */
2035 if (sc->flags & SC_SCRN_BLANKED)
2038 mark_all(sc->cur_scp);
2039 if (sc->delayed_next_scr)
2040 sc_switch_scr(sc, sc->delayed_next_scr - 1);
2041 wakeup((caddr_t)&scrn_blanked);
2045 wait_scrn_saver_stop(sc_softc_t *sc)
2049 while (scrn_blanked > 0) {
2050 run_scrn_saver = FALSE;
2051 if (sc && !(sc->flags & SC_SCRN_BLANKED)) {
2055 error = tsleep((caddr_t)&scrn_blanked, PCATCH, "scrsav", 0);
2056 if ((error != 0) && (error != ERESTART))
2059 run_scrn_saver = FALSE;
2062 #endif /* NSPLASH */
2065 sc_touch_scrn_saver(void)
2067 scsplash_stick(FALSE);
2068 run_scrn_saver = FALSE;
2072 sc_switch_scr(sc_softc_t *sc, u_int next_scr)
2078 DPRINTF(5, ("sc0: sc_switch_scr() %d ", next_scr + 1));
2080 /* prevent switch if previously requested */
2081 if (sc->flags & SC_SCRN_VTYLOCK) {
2082 sc_bell(sc->cur_scp, sc->cur_scp->bell_pitch,
2083 sc->cur_scp->bell_duration);
2087 /* delay switch if the screen is blanked or being updated */
2088 if ((sc->flags & SC_SCRN_BLANKED) || sc->write_in_progress
2089 || sc->blink_in_progress || sc->videoio_in_progress) {
2090 sc->delayed_next_scr = next_scr + 1;
2091 sc_touch_scrn_saver();
2092 DPRINTF(5, ("switch delayed\n"));
2097 cur_scp = sc->cur_scp;
2099 /* we are in the middle of the vty switching process... */
2100 if (sc->switch_in_progress
2101 && (cur_scp->smode.mode == VT_PROCESS)
2103 if (cur_scp->proc != pfind(cur_scp->pid)) {
2105 * The controlling process has died!!. Do some clean up.
2106 * NOTE:`cur_scp->proc' and `cur_scp->smode.mode'
2107 * are not reset here yet; they will be cleared later.
2109 DPRINTF(5, ("cur_scp controlling process %d died, ",
2111 if (cur_scp->status & SWITCH_WAIT_REL) {
2113 * Force the previous switch to finish, but return now
2116 DPRINTF(5, ("reset WAIT_REL, "));
2117 finish_vt_rel(cur_scp, TRUE, &s);
2119 DPRINTF(5, ("finishing previous switch\n"));
2121 } else if (cur_scp->status & SWITCH_WAIT_ACQ) {
2122 /* let's assume screen switch has been completed. */
2123 DPRINTF(5, ("reset WAIT_ACQ, "));
2124 finish_vt_acq(cur_scp);
2127 * We are in between screen release and acquisition, and
2128 * reached here via scgetc() or scrn_timer() which has
2129 * interrupted exchange_scr(). Don't do anything stupid.
2131 DPRINTF(5, ("waiting nothing, "));
2135 * The controlling process is alive, but not responding...
2136 * It is either buggy or it may be just taking time.
2137 * The following code is a gross kludge to cope with this
2138 * problem for which there is no clean solution. XXX
2140 if (cur_scp->status & SWITCH_WAIT_REL) {
2141 switch (sc->switch_in_progress++) {
2145 DPRINTF(5, ("sending relsig again, "));
2146 signal_vt_rel(cur_scp);
2153 * Act as if the controlling program returned
2156 DPRINTF(5, ("force reset WAIT_REL, "));
2157 finish_vt_rel(cur_scp, FALSE, &s);
2159 DPRINTF(5, ("act as if VT_FALSE was seen\n"));
2162 } else if (cur_scp->status & SWITCH_WAIT_ACQ) {
2163 switch (sc->switch_in_progress++) {
2167 DPRINTF(5, ("sending acqsig again, "));
2168 signal_vt_acq(cur_scp);
2174 /* clear the flag and finish the previous switch */
2175 DPRINTF(5, ("force reset WAIT_ACQ, "));
2176 finish_vt_acq(cur_scp);
2184 * Return error if an invalid argument is given, or vty switch
2185 * is still in progress.
2187 if ((next_scr < sc->first_vty) || (next_scr >= sc->first_vty + sc->vtys)
2188 || sc->switch_in_progress) {
2190 sc_bell(cur_scp, bios_value.bell_pitch, BELL_DURATION);
2191 DPRINTF(5, ("error 1\n"));
2196 * Don't allow switching away from the graphics mode vty
2197 * if the switch mode is VT_AUTO, unless the next vty is the same
2198 * as the current or the current vty has been closed (but showing).
2200 tp = VIRTUAL_TTY(sc, cur_scp->index);
2201 if ((cur_scp->index != next_scr)
2203 && (cur_scp->smode.mode == VT_AUTO)
2204 && ISGRAPHSC(cur_scp)) {
2206 sc_bell(cur_scp, bios_value.bell_pitch, BELL_DURATION);
2207 DPRINTF(5, ("error, graphics mode\n"));
2212 * Is the wanted vty open? Don't allow switching to a closed vty.
2213 * If we are in DDB, don't switch to a vty in the VT_PROCESS mode.
2214 * Note that we always allow the user to switch to the kernel
2215 * console even if it is closed.
2217 if ((sc_console == NULL) || (next_scr != sc_console->index)) {
2218 tp = VIRTUAL_TTY(sc, next_scr);
2219 if (!ISTTYOPEN(tp)) {
2221 sc_bell(cur_scp, bios_value.bell_pitch, BELL_DURATION);
2222 DPRINTF(5, ("error 2, requested vty isn't open!\n"));
2225 if ((debugger > 0) && (SC_STAT(tp->t_dev)->smode.mode == VT_PROCESS)) {
2227 DPRINTF(5, ("error 3, requested vty is in the VT_PROCESS mode\n"));
2232 /* this is the start of vty switching process... */
2233 ++sc->switch_in_progress;
2234 sc->delayed_next_scr = 0;
2235 sc->old_scp = cur_scp;
2236 sc->new_scp = SC_STAT(SC_DEV(sc, next_scr));
2237 if (sc->new_scp == sc->old_scp) {
2238 sc->switch_in_progress = 0;
2239 wakeup((caddr_t)&sc->new_scp->smode);
2241 DPRINTF(5, ("switch done (new == old)\n"));
2245 /* has controlling process died? */
2246 vt_proc_alive(sc->old_scp);
2247 vt_proc_alive(sc->new_scp);
2249 /* wait for the controlling process to release the screen, if necessary */
2250 if (signal_vt_rel(sc->old_scp)) {
2255 /* go set up the new vty screen */
2260 /* wake up processes waiting for this vty */
2261 wakeup((caddr_t)&sc->cur_scp->smode);
2263 /* wait for the controlling process to acknowledge, if necessary */
2264 if (signal_vt_acq(sc->cur_scp)) {
2269 sc->switch_in_progress = 0;
2270 if (sc->unit == sc_console_unit)
2271 cons_unavail = FALSE;
2273 DPRINTF(5, ("switch done\n"));
2279 do_switch_scr(sc_softc_t *sc, int s)
2281 vt_proc_alive(sc->new_scp);
2286 /* sc->cur_scp == sc->new_scp */
2287 wakeup((caddr_t)&sc->cur_scp->smode);
2289 /* wait for the controlling process to acknowledge, if necessary */
2290 if (!signal_vt_acq(sc->cur_scp)) {
2291 sc->switch_in_progress = 0;
2292 if (sc->unit == sc_console_unit)
2293 cons_unavail = FALSE;
2300 vt_proc_alive(scr_stat *scp)
2303 if (scp->proc == pfind(scp->pid))
2306 scp->smode.mode = VT_AUTO;
2307 DPRINTF(5, ("vt controlling process %d died\n", scp->pid));
2313 signal_vt_rel(scr_stat *scp)
2315 if (scp->smode.mode != VT_PROCESS)
2317 scp->status |= SWITCH_WAIT_REL;
2318 psignal(scp->proc, scp->smode.relsig);
2319 DPRINTF(5, ("sending relsig to %d\n", scp->pid));
2324 signal_vt_acq(scr_stat *scp)
2326 if (scp->smode.mode != VT_PROCESS)
2328 if (scp->sc->unit == sc_console_unit)
2329 cons_unavail = TRUE;
2330 scp->status |= SWITCH_WAIT_ACQ;
2331 psignal(scp->proc, scp->smode.acqsig);
2332 DPRINTF(5, ("sending acqsig to %d\n", scp->pid));
2337 finish_vt_rel(scr_stat *scp, int release, int *s)
2339 if (scp == scp->sc->old_scp && scp->status & SWITCH_WAIT_REL) {
2340 scp->status &= ~SWITCH_WAIT_REL;
2342 *s = do_switch_scr(scp->sc, *s);
2344 scp->sc->switch_in_progress = 0;
2351 finish_vt_acq(scr_stat *scp)
2353 if (scp == scp->sc->new_scp && scp->status & SWITCH_WAIT_ACQ) {
2354 scp->status &= ~SWITCH_WAIT_ACQ;
2355 scp->sc->switch_in_progress = 0;
2362 exchange_scr(sc_softc_t *sc)
2366 /* save the current state of video and keyboard */
2367 sc_move_cursor(sc->old_scp, sc->old_scp->xpos, sc->old_scp->ypos);
2368 if (!ISGRAPHSC(sc->old_scp))
2369 sc_remove_cursor_image(sc->old_scp);
2370 if (sc->old_scp->kbd_mode == K_XLATE)
2371 save_kbd_state(sc->old_scp);
2373 /* set up the video for the new screen */
2374 scp = sc->cur_scp = sc->new_scp;
2375 if (sc->old_scp->mode != scp->mode || ISUNKNOWNSC(sc->old_scp))
2378 sc_vtb_init(&scp->scr, VTB_FRAMEBUFFER, scp->xsize, scp->ysize,
2379 (void *)sc->adp->va_window, FALSE);
2380 scp->status |= MOUSE_HIDDEN;
2381 sc_move_cursor(scp, scp->xpos, scp->ypos);
2382 if (!ISGRAPHSC(scp))
2383 sc_set_cursor_image(scp);
2384 #ifndef SC_NO_PALETTE_LOADING
2385 if (ISGRAPHSC(sc->old_scp))
2386 load_palette(sc->adp, sc->palette);
2388 sc_set_border(scp, scp->border);
2390 /* set up the keyboard for the new screen */
2391 if (sc->old_scp->kbd_mode != scp->kbd_mode)
2392 kbd_ioctl(sc->kbd, KDSKBMODE, (caddr_t)&scp->kbd_mode);
2393 update_kbd_state(scp, scp->status, LOCK_MASK);
2399 sc_puts(scr_stat *scp, u_char *buf, int len)
2402 /* make screensaver happy */
2403 if (!sticky_splash && scp == scp->sc->cur_scp)
2404 run_scrn_saver = FALSE;
2408 (*scp->tsw->te_puts)(scp, buf, len);
2410 if (scp->sc->delayed_next_scr)
2411 sc_switch_scr(scp->sc, scp->sc->delayed_next_scr - 1);
2415 sc_draw_cursor_image(scr_stat *scp)
2417 /* assert(scp == scp->sc->cur_scp); */
2418 ++scp->sc->videoio_in_progress;
2419 (*scp->rndr->draw_cursor)(scp, scp->cursor_pos,
2420 scp->sc->flags & SC_BLINK_CURSOR, TRUE,
2421 sc_inside_cutmark(scp, scp->cursor_pos));
2422 scp->cursor_oldpos = scp->cursor_pos;
2423 --scp->sc->videoio_in_progress;
2427 sc_remove_cursor_image(scr_stat *scp)
2429 /* assert(scp == scp->sc->cur_scp); */
2430 ++scp->sc->videoio_in_progress;
2431 (*scp->rndr->draw_cursor)(scp, scp->cursor_oldpos,
2432 scp->sc->flags & SC_BLINK_CURSOR, FALSE,
2433 sc_inside_cutmark(scp, scp->cursor_oldpos));
2434 --scp->sc->videoio_in_progress;
2438 update_cursor_image(scr_stat *scp)
2442 if (scp->sc->flags & SC_CHAR_CURSOR) {
2443 scp->cursor_base = imax(0, scp->sc->cursor_base);
2444 scp->cursor_height = imin(scp->sc->cursor_height, scp->font_size);
2446 scp->cursor_base = 0;
2447 scp->cursor_height = scp->font_size;
2449 blink = scp->sc->flags & SC_BLINK_CURSOR;
2451 /* assert(scp == scp->sc->cur_scp); */
2452 ++scp->sc->videoio_in_progress;
2453 (*scp->rndr->draw_cursor)(scp, scp->cursor_oldpos, blink, FALSE,
2454 sc_inside_cutmark(scp, scp->cursor_pos));
2455 (*scp->rndr->set_cursor)(scp, scp->cursor_base, scp->cursor_height, blink);
2456 (*scp->rndr->draw_cursor)(scp, scp->cursor_pos, blink, TRUE,
2457 sc_inside_cutmark(scp, scp->cursor_pos));
2458 --scp->sc->videoio_in_progress;
2462 sc_set_cursor_image(scr_stat *scp)
2464 if (scp->sc->flags & SC_CHAR_CURSOR) {
2465 scp->cursor_base = imax(0, scp->sc->cursor_base);
2466 scp->cursor_height = imin(scp->sc->cursor_height, scp->font_size);
2468 scp->cursor_base = 0;
2469 scp->cursor_height = scp->font_size;
2472 /* assert(scp == scp->sc->cur_scp); */
2473 ++scp->sc->videoio_in_progress;
2474 (*scp->rndr->set_cursor)(scp, scp->cursor_base, scp->cursor_height,
2475 scp->sc->flags & SC_BLINK_CURSOR);
2476 --scp->sc->videoio_in_progress;
2480 scinit(int unit, int flags)
2483 * When syscons is being initialized as the kernel console, malloc()
2484 * is not yet functional, because various kernel structures has not been
2485 * fully initialized yet. Therefore, we need to declare the following
2486 * static buffers for the console. This is less than ideal,
2487 * but is necessry evil for the time being. XXX
2489 static scr_stat main_console;
2490 static dev_t main_devs[MAXCONS];
2491 static struct tty main_tty;
2492 static u_short sc_buffer[ROW*COL]; /* XXX */
2493 #ifndef SC_NO_FONT_LOADING
2494 static u_char font_8[256*8];
2495 static u_char font_14[256*14];
2496 static u_char font_16[256*16];
2501 video_adapter_t *adp;
2506 /* one time initialization */
2507 if (init_done == COLD)
2508 sc_get_bios_values(&bios_value);
2512 * Allocate resources. Even if we are being called for the second
2513 * time, we must allocate them again, because they might have
2516 sc = sc_get_softc(unit, flags & SC_KERNEL_CONSOLE);
2518 if (sc->adapter >= 0) {
2519 vid_release(sc->adp, (void *)&sc->adapter);
2523 if (sc->keyboard >= 0) {
2524 DPRINTF(5, ("sc%d: releasing kbd%d\n", unit, sc->keyboard));
2525 i = kbd_release(sc->kbd, (void *)&sc->keyboard);
2526 DPRINTF(5, ("sc%d: kbd_release returned %d\n", unit, i));
2527 if (sc->kbd != NULL) {
2528 DPRINTF(5, ("sc%d: kbd != NULL!, index:%d, unit:%d, flags:0x%x\n",
2529 unit, sc->kbd->kb_index, sc->kbd->kb_unit, sc->kbd->kb_flags));
2533 sc->adapter = vid_allocate("*", unit, (void *)&sc->adapter);
2534 sc->adp = vid_get_adapter(sc->adapter);
2535 /* assert((sc->adapter >= 0) && (sc->adp != NULL)) */
2536 sc->keyboard = kbd_allocate("*", unit, (void *)&sc->keyboard,
2538 DPRINTF(1, ("sc%d: keyboard %d\n", unit, sc->keyboard));
2539 sc->kbd = kbd_get_keyboard(sc->keyboard);
2540 if (sc->kbd != NULL) {
2541 DPRINTF(1, ("sc%d: kbd index:%d, unit:%d, flags:0x%x\n",
2542 unit, sc->kbd->kb_index, sc->kbd->kb_unit, sc->kbd->kb_flags));
2545 if (!(sc->flags & SC_INIT_DONE) || (adp != sc->adp)) {
2547 sc->initial_mode = sc->adp->va_initial_mode;
2549 #ifndef SC_NO_FONT_LOADING
2550 if (flags & SC_KERNEL_CONSOLE) {
2551 sc->font_8 = font_8;
2552 sc->font_14 = font_14;
2553 sc->font_16 = font_16;
2554 } else if (sc->font_8 == NULL) {
2555 /* assert(sc_malloc) */
2556 sc->font_8 = malloc(sizeof(font_8), M_DEVBUF, M_WAITOK);
2557 sc->font_14 = malloc(sizeof(font_14), M_DEVBUF, M_WAITOK);
2558 sc->font_16 = malloc(sizeof(font_16), M_DEVBUF, M_WAITOK);
2562 /* extract the hardware cursor location and hide the cursor for now */
2563 (*vidsw[sc->adapter]->read_hw_cursor)(sc->adp, &col, &row);
2564 (*vidsw[sc->adapter]->set_hw_cursor)(sc->adp, -1, -1);
2566 /* set up the first console */
2567 sc->first_vty = unit*MAXCONS;
2568 sc->vtys = MAXCONS; /* XXX: should be configurable */
2569 if (flags & SC_KERNEL_CONSOLE) {
2570 sc->dev = main_devs;
2571 sc->dev[0] = make_dev(&sc_cdevsw, unit*MAXCONS, UID_ROOT,
2572 GID_WHEEL, 0600, "ttyv%r", unit*MAXCONS);
2573 sc->dev[0]->si_tty = &main_tty;
2574 ttyregister(&main_tty);
2575 scp = &main_console;
2576 init_scp(sc, sc->first_vty, scp);
2577 sc_vtb_init(&scp->vtb, VTB_MEMORY, scp->xsize, scp->ysize,
2578 (void *)sc_buffer, FALSE);
2579 if (sc_init_emulator(scp, SC_DFLT_TERM))
2580 sc_init_emulator(scp, "*");
2581 (*scp->tsw->te_default_attr)(scp,
2582 kernel_default.std_color,
2583 kernel_default.rev_color);
2585 /* assert(sc_malloc) */
2586 sc->dev = malloc(sizeof(dev_t)*sc->vtys, M_DEVBUF, M_WAITOK);
2587 bzero(sc->dev, sizeof(dev_t)*sc->vtys);
2588 sc->dev[0] = make_dev(&sc_cdevsw, unit*MAXCONS, UID_ROOT,
2589 GID_WHEEL, 0600, "ttyv%r", unit*MAXCONS);
2590 sc->dev[0]->si_tty = ttymalloc(sc->dev[0]->si_tty);
2591 scp = alloc_scp(sc, sc->first_vty);
2593 SC_STAT(sc->dev[0]) = scp;
2596 /* copy screen to temporary buffer */
2597 sc_vtb_init(&scp->scr, VTB_FRAMEBUFFER, scp->xsize, scp->ysize,
2598 (void *)scp->sc->adp->va_window, FALSE);
2600 sc_vtb_copy(&scp->scr, 0, &scp->vtb, 0, scp->xsize*scp->ysize);
2602 /* move cursors to the initial positions */
2603 if (col >= scp->xsize)
2605 if (row >= scp->ysize)
2606 row = scp->ysize - 1;
2609 scp->cursor_pos = scp->cursor_oldpos = row*scp->xsize + col;
2610 if (bios_value.cursor_end < scp->font_size)
2611 sc->cursor_base = scp->font_size - bios_value.cursor_end - 1;
2613 sc->cursor_base = 0;
2614 i = bios_value.cursor_end - bios_value.cursor_start + 1;
2615 sc->cursor_height = imin(i, scp->font_size);
2616 #ifndef SC_NO_SYSMOUSE
2617 sc_mouse_move(scp, scp->xpixel/2, scp->ypixel/2);
2619 if (!ISGRAPHSC(scp)) {
2620 sc_set_cursor_image(scp);
2621 sc_draw_cursor_image(scp);
2624 /* save font and palette */
2625 #ifndef SC_NO_FONT_LOADING
2626 sc->fonts_loaded = 0;
2627 if (ISFONTAVAIL(sc->adp->va_flags)) {
2629 bcopy(dflt_font_8, sc->font_8, sizeof(dflt_font_8));
2630 bcopy(dflt_font_14, sc->font_14, sizeof(dflt_font_14));
2631 bcopy(dflt_font_16, sc->font_16, sizeof(dflt_font_16));
2632 sc->fonts_loaded = FONT_16 | FONT_14 | FONT_8;
2633 if (scp->font_size < 14) {
2634 sc_load_font(scp, 0, 8, sc->font_8, 0, 256);
2635 } else if (scp->font_size >= 16) {
2636 sc_load_font(scp, 0, 16, sc->font_16, 0, 256);
2638 sc_load_font(scp, 0, 14, sc->font_14, 0, 256);
2640 #else /* !SC_DFLT_FONT */
2641 if (scp->font_size < 14) {
2642 sc_save_font(scp, 0, 8, sc->font_8, 0, 256);
2643 sc->fonts_loaded = FONT_8;
2644 } else if (scp->font_size >= 16) {
2645 sc_save_font(scp, 0, 16, sc->font_16, 0, 256);
2646 sc->fonts_loaded = FONT_16;
2648 sc_save_font(scp, 0, 14, sc->font_14, 0, 256);
2649 sc->fonts_loaded = FONT_14;
2651 #endif /* SC_DFLT_FONT */
2652 /* FONT KLUDGE: always use the font page #0. XXX */
2653 sc_show_font(scp, 0);
2655 #endif /* !SC_NO_FONT_LOADING */
2657 #ifndef SC_NO_PALETTE_LOADING
2658 save_palette(sc->adp, sc->palette);
2662 if (!(sc->flags & SC_SPLASH_SCRN) && (flags & SC_KERNEL_CONSOLE)) {
2663 /* we are ready to put up the splash image! */
2664 splash_init(sc->adp, scsplash_callback, sc);
2665 sc->flags |= SC_SPLASH_SCRN;
2667 #endif /* NSPLASH */
2670 /* the rest is not necessary, if we have done it once */
2671 if (sc->flags & SC_INIT_DONE)
2674 /* initialize mapscrn arrays to a one to one map */
2675 for (i = 0; i < sizeof(sc->scr_map); i++)
2676 sc->scr_map[i] = sc->scr_rmap[i] = i;
2678 sc->flags |= SC_INIT_DONE;
2683 scterm(int unit, int flags)
2688 sc = sc_get_softc(unit, flags & SC_KERNEL_CONSOLE);
2690 return; /* shouldn't happen */
2693 /* this console is no longer available for the splash screen */
2694 if (sc->flags & SC_SPLASH_SCRN) {
2695 splash_term(sc->adp);
2696 sc->flags &= ~SC_SPLASH_SCRN;
2698 #endif /* NSPLASH */
2701 /* move the hardware cursor to the upper-left corner */
2702 (*vidsw[sc->adapter]->set_hw_cursor)(sc->adp, 0, 0);
2705 /* release the keyboard and the video card */
2706 if (sc->keyboard >= 0)
2707 kbd_release(sc->kbd, &sc->keyboard);
2708 if (sc->adapter >= 0)
2709 vid_release(sc->adp, &sc->adapter);
2711 /* stop the terminal emulator, if any */
2712 scp = SC_STAT(sc->dev[0]);
2714 (*scp->tsw->te_term)(scp, &scp->ts);
2715 if (scp->ts != NULL)
2716 free(scp->ts, M_DEVBUF);
2718 /* clear the structure */
2719 if (!(flags & SC_KERNEL_CONSOLE)) {
2720 /* XXX: We need delete_dev() for this */
2721 free(sc->dev, M_DEVBUF);
2723 /* XXX: We need a ttyunregister for this */
2724 free(sc->tty, M_DEVBUF);
2726 #ifndef SC_NO_FONT_LOADING
2727 free(sc->font_8, M_DEVBUF);
2728 free(sc->font_14, M_DEVBUF);
2729 free(sc->font_16, M_DEVBUF);
2731 /* XXX vtb, history */
2733 bzero(sc, sizeof(*sc));
2740 scshutdown(void *arg, int howto)
2742 /* assert(sc_console != NULL) */
2744 sc_touch_scrn_saver();
2745 if (!cold && sc_console
2746 && sc_console->sc->cur_scp->smode.mode == VT_AUTO
2747 && sc_console->smode.mode == VT_AUTO)
2748 sc_switch_scr(sc_console->sc, sc_console->index);
2749 shutdown_in_progress = TRUE;
2753 sc_clean_up(scr_stat *scp)
2757 #endif /* NSPLASH */
2759 if (scp->sc->flags & SC_SCRN_BLANKED) {
2760 sc_touch_scrn_saver();
2762 if ((error = wait_scrn_saver_stop(scp->sc)))
2764 #endif /* NSPLASH */
2766 scp->status |= MOUSE_HIDDEN;
2767 sc_remove_mouse_image(scp);
2768 sc_remove_cutmarking(scp);
2773 sc_alloc_scr_buffer(scr_stat *scp, int wait, int discard)
2779 sc_vtb_init(&new, VTB_MEMORY, scp->xsize, scp->ysize, NULL, wait);
2780 if (!discard && (old.vtb_flags & VTB_VALID)) {
2781 /* retain the current cursor position and buffer contants */
2782 scp->cursor_oldpos = scp->cursor_pos;
2784 * This works only if the old buffer has the same size as or larger
2785 * than the new one. XXX
2787 sc_vtb_copy(&old, 0, &new, 0, scp->xsize*scp->ysize);
2791 sc_vtb_destroy(&old);
2794 #ifndef SC_NO_SYSMOUSE
2795 /* move the mouse cursor at the center of the screen */
2796 sc_mouse_move(scp, scp->xpixel / 2, scp->ypixel / 2);
2801 *alloc_scp(sc_softc_t *sc, int vty)
2805 /* assert(sc_malloc) */
2807 scp = (scr_stat *)malloc(sizeof(scr_stat), M_DEVBUF, M_WAITOK);
2808 init_scp(sc, vty, scp);
2810 sc_alloc_scr_buffer(scp, TRUE, TRUE);
2811 if (sc_init_emulator(scp, SC_DFLT_TERM))
2812 sc_init_emulator(scp, "*");
2814 #ifndef SC_NO_CUTPASTE
2815 sc_alloc_cut_buffer(scp, TRUE);
2818 #ifndef SC_NO_HISTORY
2819 sc_alloc_history_buffer(scp, 0, 0, TRUE);
2826 init_scp(sc_softc_t *sc, int vty, scr_stat *scp)
2830 bzero(scp, sizeof(*scp));
2835 scp->mode = sc->initial_mode;
2836 (*vidsw[sc->adapter]->get_info)(sc->adp, scp->mode, &info);
2837 if (info.vi_flags & V_INFO_GRAPHICS) {
2838 scp->status |= GRAPHICS_MODE;
2839 scp->xpixel = info.vi_width;
2840 scp->ypixel = info.vi_height;
2841 scp->xsize = info.vi_width/8;
2842 scp->ysize = info.vi_height/info.vi_cheight;
2846 scp->xsize = info.vi_width;
2847 scp->ysize = info.vi_height;
2848 scp->xpixel = scp->xsize*8;
2849 scp->ypixel = scp->ysize*info.vi_cheight;
2850 if (info.vi_cheight < 14) {
2852 #ifndef SC_NO_FONT_LOADING
2853 scp->font = sc->font_8;
2857 } else if (info.vi_cheight >= 16) {
2858 scp->font_size = 16;
2859 #ifndef SC_NO_FONT_LOADING
2860 scp->font = sc->font_16;
2865 scp->font_size = 14;
2866 #ifndef SC_NO_FONT_LOADING
2867 scp->font = sc->font_14;
2873 sc_vtb_init(&scp->vtb, VTB_MEMORY, 0, 0, NULL, FALSE);
2874 sc_vtb_init(&scp->scr, VTB_FRAMEBUFFER, 0, 0, NULL, FALSE);
2875 scp->xoff = scp->yoff = 0;
2876 scp->xpos = scp->ypos = 0;
2877 scp->start = scp->xsize * scp->ysize - 1;
2882 scp->border = BG_BLACK;
2883 scp->cursor_base = sc->cursor_base;
2884 scp->cursor_height = imin(sc->cursor_height, scp->font_size);
2885 scp->mouse_cut_start = scp->xsize*scp->ysize;
2886 scp->mouse_cut_end = -1;
2887 scp->mouse_signal = 0;
2889 scp->mouse_proc = NULL;
2890 scp->kbd_mode = K_XLATE;
2891 scp->bell_pitch = bios_value.bell_pitch;
2892 scp->bell_duration = BELL_DURATION;
2893 scp->status |= (bios_value.shift_state & NLKED);
2894 scp->status |= CURSOR_ENABLED | MOUSE_HIDDEN;
2897 scp->smode.mode = VT_AUTO;
2898 scp->history = NULL;
2899 scp->history_pos = 0;
2900 scp->history_size = 0;
2904 sc_init_emulator(scr_stat *scp, char *name)
2911 if (name == NULL) /* if no name is given, use the current emulator */
2913 else /* ...otherwise find the named emulator */
2914 sw = sc_term_match(name);
2919 if (strcmp(sw->te_renderer, "*") != 0) {
2920 rndr = sc_render_match(scp, sw->te_renderer,
2921 scp->status & (GRAPHICS_MODE | PIXEL_MODE));
2924 rndr = sc_render_match(scp, scp->sc->adp->va_name,
2925 scp->status & (GRAPHICS_MODE | PIXEL_MODE));
2930 if (sw == scp->tsw) {
2931 error = (*sw->te_init)(scp, &scp->ts, SC_TE_WARM_INIT);
2933 sc_clear_screen(scp);
2934 /* assert(error == 0); */
2938 if (sc_malloc && (sw->te_size > 0))
2939 p = malloc(sw->te_size, M_DEVBUF, M_NOWAIT);
2942 error = (*sw->te_init)(scp, &p, SC_TE_COLD_INIT);
2947 (*scp->tsw->te_term)(scp, &scp->ts);
2948 if (scp->ts != NULL)
2949 free(scp->ts, M_DEVBUF);
2955 (*sw->te_default_attr)(scp, user_default.std_color, user_default.rev_color);
2956 sc_clear_screen(scp);
2962 * scgetc(flags) - get character from keyboard.
2963 * If flags & SCGETC_CN, then avoid harmful side effects.
2964 * If flags & SCGETC_NONBLOCK, then wait until a key is pressed, else
2965 * return NOKEY if there is nothing there.
2968 scgetc(sc_softc_t *sc, u_int flags)
2971 #ifndef SC_NO_HISTORY
2979 if (sc->kbd == NULL)
2984 /* I don't like this, but... XXX */
2985 if (flags & SCGETC_CN)
2986 sccnupdate(sc->cur_scp);
2989 /* first see if there is something in the keyboard port */
2991 c = kbd_read_char(sc->kbd, !(flags & SCGETC_NONBLOCK));
2993 if (!(flags & SCGETC_CN))
2994 sc_bell(scp, bios_value.bell_pitch, BELL_DURATION);
2995 } else if (c == NOKEY)
3001 /* make screensaver happy */
3003 sc_touch_scrn_saver();
3006 if (!(flags & SCGETC_CN))
3007 /* do the /dev/random device a favour */
3008 add_keyboard_randomness(c);
3011 if (scp->kbd_mode != K_XLATE)
3014 /* if scroll-lock pressed allow history browsing */
3015 if (!ISGRAPHSC(scp) && scp->history && scp->status & SLKED) {
3017 scp->status &= ~CURSOR_ENABLED;
3018 sc_remove_cursor_image(scp);
3020 #ifndef SC_NO_HISTORY
3021 if (!(scp->status & BUFFER_SAVED)) {
3022 scp->status |= BUFFER_SAVED;
3026 /* FIXME: key codes */
3027 case SPCLKEY | FKEY | F(49): /* home key */
3028 sc_remove_cutmarking(scp);
3032 case SPCLKEY | FKEY | F(57): /* end key */
3033 sc_remove_cutmarking(scp);
3037 case SPCLKEY | FKEY | F(50): /* up arrow key */
3038 sc_remove_cutmarking(scp);
3039 if (sc_hist_up_line(scp))
3040 if (!(flags & SCGETC_CN))
3041 sc_bell(scp, bios_value.bell_pitch, BELL_DURATION);
3044 case SPCLKEY | FKEY | F(58): /* down arrow key */
3045 sc_remove_cutmarking(scp);
3046 if (sc_hist_down_line(scp))
3047 if (!(flags & SCGETC_CN))
3048 sc_bell(scp, bios_value.bell_pitch, BELL_DURATION);
3051 case SPCLKEY | FKEY | F(51): /* page up key */
3052 sc_remove_cutmarking(scp);
3053 for (i=0; i<scp->ysize; i++)
3054 if (sc_hist_up_line(scp)) {
3055 if (!(flags & SCGETC_CN))
3056 sc_bell(scp, bios_value.bell_pitch, BELL_DURATION);
3061 case SPCLKEY | FKEY | F(59): /* page down key */
3062 sc_remove_cutmarking(scp);
3063 for (i=0; i<scp->ysize; i++)
3064 if (sc_hist_down_line(scp)) {
3065 if (!(flags & SCGETC_CN))
3066 sc_bell(scp, bios_value.bell_pitch, BELL_DURATION);
3071 #endif /* SC_NO_HISTORY */
3075 * Process and consume special keys here. Return a plain char code
3076 * or a char code with the META flag or a function key code.
3080 /* goto next_code */
3085 switch (KEYCHAR(c)) {
3087 case NLK: case CLK: case ALK:
3090 kbd_ioctl(sc->kbd, KDGKBSTATE, (caddr_t)&f);
3092 scp->status |= SLKED;
3094 if (scp->status & SLKED) {
3095 scp->status &= ~SLKED;
3096 #ifndef SC_NO_HISTORY
3097 if (scp->status & BUFFER_SAVED) {
3098 if (!sc_hist_restore(scp))
3099 sc_remove_cutmarking(scp);
3100 scp->status &= ~BUFFER_SAVED;
3101 scp->status |= CURSOR_ENABLED;
3102 sc_draw_cursor_image(scp);
3104 tp = VIRTUAL_TTY(sc, scp->index);
3112 /* NON-LOCKING KEYS */
3114 case LSH: case RSH: case LCTR: case RCTR:
3115 case LALT: case RALT: case ASH: case META:
3119 if (!(sc->flags & SC_SCRN_BLANKED))
3125 /* force activatation/deactivation of the screen saver */
3126 if (!(sc->flags & SC_SCRN_BLANKED)) {
3127 run_scrn_saver = TRUE;
3128 sc->scrn_time_stamp -= scrn_blank_time;
3132 * While devices are being probed, the screen saver need
3133 * to be invoked explictly. XXX
3135 if (sc->flags & SC_SCRN_BLANKED) {
3136 scsplash_stick(FALSE);
3137 stop_scrn_saver(sc, current_saver);
3139 if (!ISGRAPHSC(scp)) {
3140 scsplash_stick(TRUE);
3141 (*current_saver)(sc, TRUE);
3145 #endif /* NSPLASH */
3149 #ifndef SC_DISABLE_REBOOT
3155 #ifndef SC_DISABLE_REBOOT
3156 shutdown_nice(RB_HALT);
3161 #ifndef SC_DISABLE_REBOOT
3162 shutdown_nice(RB_HALT|RB_POWEROFF);
3168 apm_suspend(PMST_SUSPEND);
3171 apm_suspend(PMST_STANDBY);
3180 #ifndef SC_DISABLE_DDBKEY
3182 Debugger("manual escape to debugger");
3184 printf("No debugger in kernel\n");
3186 #else /* SC_DISABLE_DDBKEY */
3188 #endif /* SC_DISABLE_DDBKEY */
3192 if (enable_panic_key)
3193 panic("Forced by the panic key");
3197 this_scr = scp->index;
3198 for (i = (this_scr - sc->first_vty + 1)%sc->vtys;
3199 sc->first_vty + i != this_scr;
3200 i = (i + 1)%sc->vtys) {
3201 struct tty *tp = VIRTUAL_TTY(sc, sc->first_vty + i);
3202 if (ISTTYOPEN(tp)) {
3203 sc_switch_scr(scp->sc, sc->first_vty + i);
3210 this_scr = scp->index;
3211 for (i = (this_scr - sc->first_vty + sc->vtys - 1)%sc->vtys;
3212 sc->first_vty + i != this_scr;
3213 i = (i + sc->vtys - 1)%sc->vtys) {
3214 struct tty *tp = VIRTUAL_TTY(sc, sc->first_vty + i);
3215 if (ISTTYOPEN(tp)) {
3216 sc_switch_scr(scp->sc, sc->first_vty + i);
3223 if (KEYCHAR(c) >= F_SCR && KEYCHAR(c) <= L_SCR) {
3224 sc_switch_scr(scp->sc, sc->first_vty + KEYCHAR(c) - F_SCR);
3227 /* assert(c & FKEY) */
3228 if (!(sc->flags & SC_SCRN_BLANKED))
3232 /* goto next_code */
3234 /* regular keys (maybe MKEY is set) */
3235 if (!(sc->flags & SC_SCRN_BLANKED))
3244 scmmap(dev_t dev, vm_offset_t offset, int nprot)
3249 if (scp != scp->sc->cur_scp)
3251 return (*vidsw[scp->sc->adapter]->mmap)(scp->sc->adp, offset, nprot);
3255 save_kbd_state(scr_stat *scp)
3260 error = kbd_ioctl(scp->sc->kbd, KDGKBSTATE, (caddr_t)&state);
3261 if (error == ENOIOCTL)
3264 scp->status &= ~LOCK_MASK;
3265 scp->status |= state;
3271 update_kbd_state(scr_stat *scp, int new_bits, int mask)
3276 if (mask != LOCK_MASK) {
3277 error = kbd_ioctl(scp->sc->kbd, KDGKBSTATE, (caddr_t)&state);
3278 if (error == ENOIOCTL)
3283 state |= new_bits & mask;
3285 state = new_bits & LOCK_MASK;
3287 error = kbd_ioctl(scp->sc->kbd, KDSKBSTATE, (caddr_t)&state);
3288 if (error == ENOIOCTL)
3294 update_kbd_leds(scr_stat *scp, int which)
3299 error = kbd_ioctl(scp->sc->kbd, KDSETLED, (caddr_t)&which);
3300 if (error == ENOIOCTL)
3306 set_mode(scr_stat *scp)
3310 /* reject unsupported mode */
3311 if ((*vidsw[scp->sc->adapter]->get_info)(scp->sc->adp, scp->mode, &info))
3314 /* if this vty is not currently showing, do nothing */
3315 if (scp != scp->sc->cur_scp)
3318 /* setup video hardware for the given mode */
3319 (*vidsw[scp->sc->adapter]->set_mode)(scp->sc->adp, scp->mode);
3320 sc_vtb_init(&scp->scr, VTB_FRAMEBUFFER, scp->xsize, scp->ysize,
3321 (void *)scp->sc->adp->va_window, FALSE);
3323 #ifndef SC_NO_FONT_LOADING
3324 /* load appropriate font */
3325 if (!(scp->status & GRAPHICS_MODE)) {
3326 if (!(scp->status & PIXEL_MODE) && ISFONTAVAIL(scp->sc->adp->va_flags)) {
3327 if (scp->font_size < 14) {
3328 if (scp->sc->fonts_loaded & FONT_8)
3329 sc_load_font(scp, 0, 8, scp->sc->font_8, 0, 256);
3330 } else if (scp->font_size >= 16) {
3331 if (scp->sc->fonts_loaded & FONT_16)
3332 sc_load_font(scp, 0, 16, scp->sc->font_16, 0, 256);
3334 if (scp->sc->fonts_loaded & FONT_14)
3335 sc_load_font(scp, 0, 14, scp->sc->font_14, 0, 256);
3339 * This is an interim kludge to display correct font.
3340 * Always use the font page #0 on the video plane 2.
3341 * Somehow we cannot show the font in other font pages on
3342 * some video cards... XXX
3344 sc_show_font(scp, 0);
3348 #endif /* !SC_NO_FONT_LOADING */
3350 sc_set_border(scp, scp->border);
3351 sc_set_cursor_image(scp);
3357 sc_set_border(scr_stat *scp, int color)
3359 ++scp->sc->videoio_in_progress;
3360 (*scp->rndr->draw_border)(scp, color);
3361 --scp->sc->videoio_in_progress;
3364 #ifndef SC_NO_FONT_LOADING
3366 sc_load_font(scr_stat *scp, int page, int size, u_char *buf,
3367 int base, int count)
3372 sc->font_loading_in_progress = TRUE;
3373 (*vidsw[sc->adapter]->load_font)(sc->adp, page, size, buf, base, count);
3374 sc->font_loading_in_progress = FALSE;
3378 sc_save_font(scr_stat *scp, int page, int size, u_char *buf,
3379 int base, int count)
3384 sc->font_loading_in_progress = TRUE;
3385 (*vidsw[sc->adapter]->save_font)(sc->adp, page, size, buf, base, count);
3386 sc->font_loading_in_progress = FALSE;
3390 sc_show_font(scr_stat *scp, int page)
3392 (*vidsw[scp->sc->adapter]->show_font)(scp->sc->adp, page);
3394 #endif /* !SC_NO_FONT_LOADING */
3397 sc_paste(scr_stat *scp, u_char *p, int count)
3402 if (scp->status & MOUSE_VISIBLE) {
3403 tp = VIRTUAL_TTY(scp->sc, scp->sc->cur_scp->index);
3406 rmap = scp->sc->scr_rmap;
3407 for (; count > 0; --count)
3408 (*linesw[tp->t_line].l_rint)(rmap[*p++], tp);
3413 sc_bell(scr_stat *scp, int pitch, int duration)
3415 if (cold || shutdown_in_progress)
3418 if (scp != scp->sc->cur_scp && (scp->sc->flags & SC_QUIET_BELL))
3421 if (scp->sc->flags & SC_VISUAL_BELL) {
3422 if (scp->sc->blink_in_progress)
3424 scp->sc->blink_in_progress = 3;
3425 if (scp != scp->sc->cur_scp)
3426 scp->sc->blink_in_progress += 2;
3427 blink_screen(scp->sc->cur_scp);
3428 } else if (duration != 0 && pitch != 0) {
3429 if (scp != scp->sc->cur_scp)
3431 sysbeep(pitch, duration);
3436 blink_screen(void *arg)
3438 scr_stat *scp = arg;
3441 if (ISGRAPHSC(scp) || (scp->sc->blink_in_progress <= 1)) {
3442 scp->sc->blink_in_progress = 0;
3444 tp = VIRTUAL_TTY(scp->sc, scp->index);
3447 if (scp->sc->delayed_next_scr)
3448 sc_switch_scr(scp->sc, scp->sc->delayed_next_scr - 1);
3451 (*scp->rndr->draw)(scp, 0, scp->xsize*scp->ysize,
3452 scp->sc->blink_in_progress & 1);
3453 scp->sc->blink_in_progress--;
3454 timeout(blink_screen, scp, hz / 10);