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: src/sys/dev/syscons/syscons.c,v 1.336.2.15 2002/10/24 00:35:31 kbyanc Exp $
29 * $DragonFly: src/sys/dev/misc/syscons/syscons.c,v 1.4 2003/06/25 03:55:50 dillon Exp $
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/kbd/kbdreg.h>
63 #include <dev/fb/fbreg.h>
64 #include <dev/fb/splashreg.h>
65 #include <dev/syscons/syscons.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 = {
208 /* write */ ttywrite,
212 /* strategy */ nostrategy,
214 /* maj */ CDEV_MAJOR,
217 /* flags */ D_TTY | D_KQFILTER,
219 /* kqfilter */ ttykqfilter
223 sc_probe_unit(int unit, int flags)
225 if (!scvidprobe(unit, flags, FALSE)) {
227 printf("sc%d: no video adapter found.\n", unit);
231 /* syscons will be attached even when there is no keyboard */
232 sckbdprobe(unit, flags, FALSE);
237 /* probe video adapters, return TRUE if found */
239 scvidprobe(int unit, int flags, int cons)
242 * Access the video adapter driver through the back door!
243 * Video adapter drivers need to be configured before syscons.
244 * However, when syscons is being probed as the low-level console,
245 * they have not been initialized yet. We force them to initialize
246 * themselves here. XXX
248 vid_configure(cons ? VIO_PROBE_ONLY : 0);
250 return (vid_find_adapter("*", unit) >= 0);
253 /* probe the keyboard, return TRUE if found */
255 sckbdprobe(int unit, int flags, int cons)
257 /* access the keyboard driver through the backdoor! */
258 kbd_configure(cons ? KB_CONF_PROBE_ONLY : 0);
260 return (kbd_find_keyboard("*", unit) >= 0);
264 *adapter_name(video_adapter_t *adp)
270 { KD_MONO, { "MDA", "MDA" } },
271 { KD_HERCULES, { "Hercules", "Hercules" } },
272 { KD_CGA, { "CGA", "CGA" } },
273 { KD_EGA, { "EGA", "EGA (mono)" } },
274 { KD_VGA, { "VGA", "VGA (mono)" } },
275 { KD_PC98, { "PC-98x1", "PC-98x1" } },
276 { KD_TGA, { "TGA", "TGA" } },
277 { -1, { "Unknown", "Unknown" } },
281 for (i = 0; names[i].type != -1; ++i)
282 if (names[i].type == adp->va_type)
284 return names[i].name[(adp->va_flags & V_ADP_COLOR) ? 0 : 1];
288 sc_attach_unit(int unit, int flags)
298 flags &= ~SC_KERNEL_CONSOLE;
300 if (sc_console_unit == unit) {
302 * If this unit is being used as the system console, we need to
303 * adjust some variables and buffers before and after scinit().
305 /* assert(sc_console != NULL) */
306 flags |= SC_KERNEL_CONSOLE;
311 if (sc_console->tsw->te_size > 0) {
312 /* assert(sc_console->ts != NULL); */
313 kernel_console_ts = sc_console->ts;
314 sc_console->ts = malloc(sc_console->tsw->te_size,
316 bcopy(kernel_console_ts, sc_console->ts, sc_console->tsw->te_size);
317 (*sc_console->tsw->te_default_attr)(sc_console,
318 user_default.std_color,
319 user_default.rev_color);
325 sc = sc_get_softc(unit, flags & SC_KERNEL_CONSOLE);
327 scp = SC_STAT(sc->dev[0]);
328 if (sc_console == NULL) /* sc_console_unit < 0 */
332 if ((sc->config & SC_VESA800X600)
333 && ((*vidsw[sc->adapter]->get_info)(sc->adp, M_VESA_800x600, &info) == 0)) {
335 if (sc->flags & SC_SPLASH_SCRN)
336 splash_term(sc->adp);
338 sc_set_graphics_mode(scp, NULL, M_VESA_800x600);
339 sc_set_pixel_mode(scp, NULL, COL, ROW, 16);
340 sc->initial_mode = M_VESA_800x600;
342 /* put up the splash again! */
343 if (sc->flags & SC_SPLASH_SCRN)
344 splash_init(sc->adp, scsplash_callback, sc);
347 #endif /* SC_PIXEL_MODE */
349 /* initialize cursor */
351 update_cursor_image(scp);
353 /* get screen update going */
356 /* set up the keyboard */
357 kbd_ioctl(sc->kbd, KDSKBMODE, (caddr_t)&scp->kbd_mode);
358 update_kbd_state(scp, scp->status, LOCK_MASK);
360 printf("sc%d: %s <%d virtual consoles, flags=0x%x>\n",
361 unit, adapter_name(sc->adp), sc->vtys, sc->config);
363 printf("sc%d:", unit);
364 if (sc->adapter >= 0)
365 printf(" fb%d", sc->adapter);
366 if (sc->keyboard >= 0)
367 printf(", kbd%d", sc->keyboard);
369 printf(", terminal emulator: %s (%s)",
370 scp->tsw->te_name, scp->tsw->te_desc);
374 /* register a shutdown callback for the kernel console */
375 if (sc_console_unit == unit)
376 EVENTHANDLER_REGISTER(shutdown_pre_sync, scshutdown,
377 (void *)(uintptr_t)unit, SHUTDOWN_PRI_DEFAULT);
379 for (vc = 0; vc < sc->vtys; vc++) {
380 dev = make_dev(&sc_cdevsw, vc + unit * MAXCONS,
381 UID_ROOT, GID_WHEEL, 0600, "ttyv%r", vc + unit * MAXCONS);
384 * The first vty already has struct tty and scr_stat initialized
385 * in scinit(). The other vtys will have these structs when
390 dev = make_dev(&sc_cdevsw, SC_CONSOLECTL,
391 UID_ROOT, GID_WHEEL, 0600, "consolectl");
392 dev->si_tty = sc_console_tty = ttymalloc(sc_console_tty);
393 SC_STAT(dev) = sc_console;
406 * As soon as malloc() becomes functional, we had better allocate
407 * various buffers for the kernel console.
410 if (sc_console_unit < 0) /* sc_console == NULL */
413 /* copy the temporary buffer to the final buffer */
414 sc_alloc_scr_buffer(sc_console, FALSE, FALSE);
416 #ifndef SC_NO_CUTPASTE
417 sc_alloc_cut_buffer(sc_console, FALSE);
420 #ifndef SC_NO_HISTORY
421 /* initialize history buffer & pointers */
422 sc_alloc_history_buffer(sc_console, 0, 0, FALSE);
427 SYSINIT(sc_mem, SI_SUB_KMEM, SI_ORDER_ANY, scmeminit, NULL);
430 scdevtounit(dev_t dev)
432 int vty = SC_VTY(dev);
434 if (vty == SC_CONSOLECTL)
435 return ((sc_console != NULL) ? sc_console->sc->unit : -1);
436 else if ((vty < 0) || (vty >= MAXCONS*sc_max_unit()))
443 scopen(dev_t dev, int flag, int mode, struct thread *td)
445 int unit = scdevtounit(dev);
452 DPRINTF(5, ("scopen: dev:%d,%d, unit:%d, vty:%d\n",
453 major(dev), minor(dev), unit, SC_VTY(dev)));
455 sc = sc_get_softc(unit, (sc_console_unit == unit) ? SC_KERNEL_CONSOLE : 0);
459 tp = dev->si_tty = ttymalloc(dev->si_tty);
460 tp->t_oproc = scstart;
461 tp->t_param = scparam;
462 tp->t_stop = nottystop;
464 if (!ISTTYOPEN(tp)) {
466 /* Use the current setting of the <-- key as default VERASE. */
467 /* If the Delete key is preferable, an stty is necessary */
468 if (sc->kbd != NULL) {
469 key.keynum = KEYCODE_BS;
470 kbd_ioctl(sc->kbd, GIO_KEYMAPENT, (caddr_t)&key);
471 tp->t_cc[VERASE] = key.key.map[0];
473 tp->t_iflag = TTYDEF_IFLAG;
474 tp->t_oflag = TTYDEF_OFLAG;
475 tp->t_cflag = TTYDEF_CFLAG;
476 tp->t_lflag = TTYDEF_LFLAG;
477 tp->t_ispeed = tp->t_ospeed = TTYDEF_SPEED;
478 scparam(tp, &tp->t_termios);
479 (*linesw[tp->t_line].l_modem)(tp, 1);
482 if (tp->t_state & TS_XCLUDE && suser(td))
485 error = (*linesw[tp->t_line].l_open)(dev, tp);
489 scp = SC_STAT(dev) = alloc_scp(sc, SC_VTY(dev));
491 sc_set_pixel_mode(scp, NULL, COL, ROW, 16);
493 if (!tp->t_winsize.ws_col && !tp->t_winsize.ws_row) {
494 tp->t_winsize.ws_col = scp->xsize;
495 tp->t_winsize.ws_row = scp->ysize;
502 scclose(dev_t dev, int flag, int mode, struct thread *td)
504 struct tty *tp = dev->si_tty;
508 if (SC_VTY(dev) != SC_CONSOLECTL) {
509 scp = SC_STAT(tp->t_dev);
510 /* were we in the middle of the VT switching process? */
511 DPRINTF(5, ("sc%d: scclose(), ", scp->sc->unit));
513 if ((scp == scp->sc->cur_scp) && (scp->sc->unit == sc_console_unit))
514 cons_unavail = FALSE;
515 if (finish_vt_rel(scp, TRUE, &s) == 0) /* force release */
516 DPRINTF(5, ("reset WAIT_REL, "));
517 if (finish_vt_acq(scp) == 0) /* force acknowledge */
518 DPRINTF(5, ("reset WAIT_ACQ, "));
520 if (scp == &main_console) {
523 scp->smode.mode = VT_AUTO;
526 sc_vtb_destroy(&scp->vtb);
527 sc_vtb_destroy(&scp->scr);
528 sc_free_history_buffer(scp, scp->ysize);
535 scp->smode.mode = VT_AUTO;
537 scp->kbd_mode = K_XLATE;
538 if (scp == scp->sc->cur_scp)
539 kbd_ioctl(scp->sc->kbd, KDSKBMODE, (caddr_t)&scp->kbd_mode);
540 DPRINTF(5, ("done.\n"));
543 (*linesw[tp->t_line].l_close)(tp, flag);
550 scread(dev_t dev, struct uio *uio, int flag)
552 sc_touch_scrn_saver();
553 return ttyread(dev, uio, flag);
557 sckbdevent(keyboard_t *thiskbd, int event, void *arg)
565 sc = (sc_softc_t *)arg;
566 /* assert(thiskbd == sc->kbd) */
571 case KBDIO_UNLOADING:
574 kbd_release(thiskbd, (void *)&sc->keyboard);
581 * Loop while there is still input to get from the keyboard.
582 * I don't think this is nessesary, and it doesn't fix
583 * the Xaccel-2.1 keyboard hang, but it can't hurt. XXX
585 while ((c = scgetc(sc, SCGETC_NONBLOCK)) != NOKEY) {
587 cur_tty = VIRTUAL_TTY(sc, sc->cur_scp->index);
588 if (!ISTTYOPEN(cur_tty)) {
589 cur_tty = sc_console_tty;
590 if (!ISTTYOPEN(cur_tty))
594 if ((*sc->cur_scp->tsw->te_input)(sc->cur_scp, c, cur_tty))
597 switch (KEYFLAGS(c)) {
598 case 0x0000: /* normal key */
599 (*linesw[cur_tty->t_line].l_rint)(KEYCHAR(c), cur_tty);
601 case FKEY: /* function key, return string */
602 cp = kbd_get_fkeystr(thiskbd, KEYCHAR(c), &len);
605 (*linesw[cur_tty->t_line].l_rint)(*cp++, cur_tty);
608 case MKEY: /* meta is active, prepend ESC */
609 (*linesw[cur_tty->t_line].l_rint)(0x1b, cur_tty);
610 (*linesw[cur_tty->t_line].l_rint)(KEYCHAR(c), cur_tty);
612 case BKEY: /* backtab fixed sequence (esc [ Z) */
613 (*linesw[cur_tty->t_line].l_rint)(0x1b, cur_tty);
614 (*linesw[cur_tty->t_line].l_rint)('[', cur_tty);
615 (*linesw[cur_tty->t_line].l_rint)('Z', cur_tty);
620 sc->cur_scp->status |= MOUSE_HIDDEN;
626 scparam(struct tty *tp, struct termios *t)
628 tp->t_ispeed = t->c_ispeed;
629 tp->t_ospeed = t->c_ospeed;
630 tp->t_cflag = t->c_cflag;
635 scioctl(dev_t dev, u_long cmd, caddr_t data, int flag, struct thread *td)
643 struct proc *p = td->td_proc;
649 /* If there is a user_ioctl function call that first */
651 error = (*sc_user_ioctl)(dev, cmd, data, flag, td);
652 if (error != ENOIOCTL)
656 error = sc_vid_ioctl(tp, cmd, data, flag, td);
657 if (error != ENOIOCTL)
660 #ifndef SC_NO_HISTORY
661 error = sc_hist_ioctl(tp, cmd, data, flag, td);
662 if (error != ENOIOCTL)
666 #ifndef SC_NO_SYSMOUSE
667 error = sc_mouse_ioctl(tp, cmd, data, flag, td);
668 if (error != ENOIOCTL)
672 scp = SC_STAT(tp->t_dev);
673 /* assert(scp != NULL) */
674 /* scp is sc_console, if SC_VTY(dev) == SC_CONSOLECTL. */
678 error = (*scp->tsw->te_ioctl)(scp, tp, cmd, data, flag, td);
679 if (error != ENOIOCTL)
683 switch (cmd) { /* process console hardware related ioctl's */
685 case GIO_ATTR: /* get current attributes */
686 /* this ioctl is not processed here, but in the terminal emulator */
689 case GIO_COLOR: /* is this a color console ? */
690 *(int *)data = (sc->adp->va_flags & V_ADP_COLOR) ? 1 : 0;
693 case CONS_BLANKTIME: /* set screen saver timeout (0 = no saver) */
694 if (*(int *)data < 0 || *(int *)data > MAX_BLANKTIME)
697 scrn_blank_time = *(int *)data;
698 run_scrn_saver = (scrn_blank_time != 0);
702 case CONS_CURSORTYPE: /* set cursor type blink/noblink */
704 if (!ISGRAPHSC(sc->cur_scp))
705 sc_remove_cursor_image(sc->cur_scp);
706 if ((*(int*)data) & 0x01)
707 sc->flags |= SC_BLINK_CURSOR;
709 sc->flags &= ~SC_BLINK_CURSOR;
710 if ((*(int*)data) & 0x02) {
711 sc->flags |= SC_CHAR_CURSOR;
713 sc->flags &= ~SC_CHAR_CURSOR;
715 * The cursor shape is global property; all virtual consoles
716 * are affected. Update the cursor in the current console...
718 if (!ISGRAPHSC(sc->cur_scp)) {
719 sc_set_cursor_image(sc->cur_scp);
720 sc_draw_cursor_image(sc->cur_scp);
725 case CONS_BELLTYPE: /* set bell type sound/visual */
726 if ((*(int *)data) & 0x01)
727 sc->flags |= SC_VISUAL_BELL;
729 sc->flags &= ~SC_VISUAL_BELL;
730 if ((*(int *)data) & 0x02)
731 sc->flags |= SC_QUIET_BELL;
733 sc->flags &= ~SC_QUIET_BELL;
736 case CONS_GETINFO: /* get current (virtual) console info */
738 vid_info_t *ptr = (vid_info_t*)data;
739 if (ptr->size == sizeof(struct vid_info)) {
740 ptr->m_num = sc->cur_scp->index;
741 ptr->font_size = scp->font_size;
742 ptr->mv_col = scp->xpos;
743 ptr->mv_row = scp->ypos;
744 ptr->mv_csz = scp->xsize;
745 ptr->mv_rsz = scp->ysize;
747 * The following fields are filled by the terminal emulator. XXX
754 ptr->mv_grfc.fore = 0; /* not supported */
755 ptr->mv_grfc.back = 0; /* not supported */
756 ptr->mv_ovscan = scp->border;
757 if (scp == sc->cur_scp)
759 ptr->mk_keylock = scp->status & LOCK_MASK;
765 case CONS_GETVERS: /* get version number */
766 *(int*)data = 0x200; /* version 2.0 */
769 case CONS_IDLE: /* see if the screen has been idle */
771 * When the screen is in the GRAPHICS_MODE or UNKNOWN_MODE,
772 * the user process may have been writing something on the
773 * screen and syscons is not aware of it. Declare the screen
774 * is NOT idle if it is in one of these modes. But there is
775 * an exception to it; if a screen saver is running in the
776 * graphics mode in the current screen, we should say that the
777 * screen has been idle.
779 *(int *)data = (sc->flags & SC_SCRN_IDLE)
780 && (!ISGRAPHSC(sc->cur_scp)
781 || (sc->cur_scp->status & SAVER_RUNNING));
784 case CONS_SAVERMODE: /* set saver mode */
785 switch(*(int *)data) {
788 /* if a LKM screen saver is running, stop it first. */
789 scsplash_stick(FALSE);
790 saver_mode = *(int *)data;
793 if ((error = wait_scrn_saver_stop(NULL))) {
798 run_scrn_saver = TRUE;
799 if (saver_mode == CONS_USR_SAVER)
800 scp->status |= SAVER_RUNNING;
802 scp->status &= ~SAVER_RUNNING;
803 scsplash_stick(TRUE);
808 if ((saver_mode == CONS_USR_SAVER) && (scp->status & SAVER_RUNNING))
809 scp->status &= ~SAVER_RUNNING;
810 saver_mode = *(int *)data;
818 case CONS_SAVERSTART: /* immediately start/stop the screen saver */
820 * Note that this ioctl does not guarantee the screen saver
821 * actually starts or stops. It merely attempts to do so...
824 run_scrn_saver = (*(int *)data != 0);
826 sc->scrn_time_stamp -= scrn_blank_time;
830 case CONS_SCRSHOT: /* get a screen shot */
832 scrshot_t *ptr = (scrshot_t*)data;
834 if (ISGRAPHSC(scp)) {
838 if (scp->xsize != ptr->xsize || scp->ysize != ptr->ysize) {
842 copyout ((void*)scp->vtb.vtb_buffer, ptr->buf,
843 ptr->xsize * ptr->ysize * sizeof(u_int16_t));
848 case VT_SETMODE: /* set screen switcher mode */
850 struct vt_mode *mode;
852 mode = (struct vt_mode *)data;
853 DPRINTF(5, ("sc%d: VT_SETMODE ", sc->unit));
854 if (scp->smode.mode == VT_PROCESS) {
855 if (scp->proc == pfind(scp->pid) && scp->proc != p) {
856 DPRINTF(5, ("error EPERM\n"));
861 if (mode->mode == VT_AUTO) {
862 scp->smode.mode = VT_AUTO;
865 DPRINTF(5, ("VT_AUTO, "));
866 if ((scp == sc->cur_scp) && (sc->unit == sc_console_unit))
867 cons_unavail = FALSE;
868 /* were we in the middle of the vty switching process? */
869 if (finish_vt_rel(scp, TRUE, &s) == 0)
870 DPRINTF(5, ("reset WAIT_REL, "));
871 if (finish_vt_acq(scp) == 0)
872 DPRINTF(5, ("reset WAIT_ACQ, "));
874 if (!ISSIGVALID(mode->relsig) || !ISSIGVALID(mode->acqsig)
875 || !ISSIGVALID(mode->frsig)) {
877 DPRINTF(5, ("error EINVAL\n"));
880 DPRINTF(5, ("VT_PROCESS %d, ", p->p_pid));
881 bcopy(data, &scp->smode, sizeof(struct vt_mode));
883 scp->pid = scp->proc->p_pid;
884 if ((scp == sc->cur_scp) && (sc->unit == sc_console_unit))
892 case VT_GETMODE: /* get screen switcher mode */
893 bcopy(&scp->smode, data, sizeof(struct vt_mode));
896 case VT_RELDISP: /* screen switcher ioctl */
899 * This must be the current vty which is in the VT_PROCESS
902 if ((scp != sc->cur_scp) || (scp->smode.mode != VT_PROCESS)) {
906 /* ...and this process is controlling it. */
907 if (scp->proc != p) {
912 switch(*(int *)data) {
913 case VT_FALSE: /* user refuses to release screen, abort */
914 if ((error = finish_vt_rel(scp, FALSE, &s)) == 0)
915 DPRINTF(5, ("sc%d: VT_FALSE\n", sc->unit));
917 case VT_TRUE: /* user has released screen, go on */
918 if ((error = finish_vt_rel(scp, TRUE, &s)) == 0)
919 DPRINTF(5, ("sc%d: VT_TRUE\n", sc->unit));
921 case VT_ACKACQ: /* acquire acknowledged, switch completed */
922 if ((error = finish_vt_acq(scp)) == 0)
923 DPRINTF(5, ("sc%d: VT_ACKACQ\n", sc->unit));
931 case VT_OPENQRY: /* return free virtual console */
932 for (i = sc->first_vty; i < sc->first_vty + sc->vtys; i++) {
933 tp = VIRTUAL_TTY(sc, i);
934 if (!ISTTYOPEN(tp)) {
935 *(int *)data = i + 1;
941 case VT_ACTIVATE: /* switch to screen *data */
942 i = (*(int *)data == 0) ? scp->index : (*(int *)data - 1);
944 sc_clean_up(sc->cur_scp);
946 return sc_switch_scr(sc, i);
948 case VT_WAITACTIVE: /* wait for switch to occur */
949 i = (*(int *)data == 0) ? scp->index : (*(int *)data - 1);
950 if ((i < sc->first_vty) || (i >= sc->first_vty + sc->vtys))
953 error = sc_clean_up(sc->cur_scp);
957 scp = SC_STAT(SC_DEV(sc, i));
958 if (scp == scp->sc->cur_scp)
960 while ((error=tsleep((caddr_t)&scp->smode, PZERO|PCATCH,
961 "waitvt", 0)) == ERESTART) ;
964 case VT_GETACTIVE: /* get active vty # */
965 *(int *)data = sc->cur_scp->index + 1;
968 case VT_GETINDEX: /* get this vty # */
969 *(int *)data = scp->index + 1;
972 case VT_LOCKSWITCH: /* prevent vty switching */
973 if ((*(int *)data) & 0x01)
974 sc->flags |= SC_SCRN_VTYLOCK;
976 sc->flags &= ~SC_SCRN_VTYLOCK;
979 case KDENABIO: /* allow io operations */
986 p->p_md.md_regs->tf_eflags |= PSL_IOPL;
990 case KDDISABIO: /* disallow io operations (default) */
992 p->p_md.md_regs->tf_eflags &= ~PSL_IOPL;
996 case KDSKBSTATE: /* set keyboard state (locks) */
997 if (*(int *)data & ~LOCK_MASK)
999 scp->status &= ~LOCK_MASK;
1000 scp->status |= *(int *)data;
1001 if (scp == sc->cur_scp)
1002 update_kbd_state(scp, scp->status, LOCK_MASK);
1005 case KDGKBSTATE: /* get keyboard state (locks) */
1006 if (scp == sc->cur_scp)
1007 save_kbd_state(scp);
1008 *(int *)data = scp->status & LOCK_MASK;
1011 case KDGETREPEAT: /* get keyboard repeat & delay rates */
1012 case KDSETREPEAT: /* set keyboard repeat & delay rates (new) */
1013 error = kbd_ioctl(sc->kbd, cmd, data);
1014 if (error == ENOIOCTL)
1018 case KDSETRAD: /* set keyboard repeat & delay rates (old) */
1019 if (*(int *)data & ~0x7f)
1021 error = kbd_ioctl(sc->kbd, cmd, data);
1022 if (error == ENOIOCTL)
1026 case KDSKBMODE: /* set keyboard mode */
1027 switch (*(int *)data) {
1028 case K_XLATE: /* switch to XLT ascii mode */
1029 case K_RAW: /* switch to RAW scancode mode */
1030 case K_CODE: /* switch to CODE mode */
1031 scp->kbd_mode = *(int *)data;
1032 if (scp == sc->cur_scp)
1033 kbd_ioctl(sc->kbd, cmd, data);
1040 case KDGKBMODE: /* get keyboard mode */
1041 *(int *)data = scp->kbd_mode;
1045 error = kbd_ioctl(sc->kbd, cmd, data);
1046 if (error == ENOIOCTL)
1050 case KDMKTONE: /* sound the bell */
1052 sc_bell(scp, (*(int*)data)&0xffff,
1053 (((*(int*)data)>>16)&0xffff)*hz/1000);
1055 sc_bell(scp, scp->bell_pitch, scp->bell_duration);
1058 case KIOCSOUND: /* make tone (*data) hz */
1059 if (scp == sc->cur_scp) {
1061 return sc_tone(*(int *)data);
1067 case KDGKBTYPE: /* get keyboard type */
1068 error = kbd_ioctl(sc->kbd, cmd, data);
1069 if (error == ENOIOCTL) {
1070 /* always return something? XXX */
1075 case KDSETLED: /* set keyboard LED status */
1076 if (*(int *)data & ~LED_MASK) /* FIXME: LOCK_MASK? */
1078 scp->status &= ~LED_MASK;
1079 scp->status |= *(int *)data;
1080 if (scp == sc->cur_scp)
1081 update_kbd_leds(scp, scp->status);
1084 case KDGETLED: /* get keyboard LED status */
1085 if (scp == sc->cur_scp)
1086 save_kbd_state(scp);
1087 *(int *)data = scp->status & LED_MASK;
1090 case CONS_SETKBD: /* set the new keyboard */
1095 newkbd = kbd_get_keyboard(*(int *)data);
1096 if (newkbd == NULL) {
1101 if (sc->kbd != newkbd) {
1102 i = kbd_allocate(newkbd->kb_name, newkbd->kb_unit,
1103 (void *)&sc->keyboard, sckbdevent, sc);
1104 /* i == newkbd->kb_index */
1106 if (sc->kbd != NULL) {
1107 save_kbd_state(sc->cur_scp);
1108 kbd_release(sc->kbd, (void *)&sc->keyboard);
1110 sc->kbd = kbd_get_keyboard(i); /* sc->kbd == newkbd */
1112 kbd_ioctl(sc->kbd, KDSKBMODE,
1113 (caddr_t)&sc->cur_scp->kbd_mode);
1114 update_kbd_state(sc->cur_scp, sc->cur_scp->status,
1117 error = EPERM; /* XXX */
1124 case CONS_RELKBD: /* release the current keyboard */
1127 if (sc->kbd != NULL) {
1128 save_kbd_state(sc->cur_scp);
1129 error = kbd_release(sc->kbd, (void *)&sc->keyboard);
1138 case CONS_GETTERM: /* get the current terminal emulator info */
1142 if (((term_info_t *)data)->ti_index == 0) {
1145 sw = sc_term_match_by_number(((term_info_t *)data)->ti_index);
1148 strncpy(((term_info_t *)data)->ti_name, sw->te_name,
1149 sizeof(((term_info_t *)data)->ti_name));
1150 strncpy(((term_info_t *)data)->ti_desc, sw->te_desc,
1151 sizeof(((term_info_t *)data)->ti_desc));
1152 ((term_info_t *)data)->ti_flags = 0;
1155 ((term_info_t *)data)->ti_name[0] = '\0';
1156 ((term_info_t *)data)->ti_desc[0] = '\0';
1157 ((term_info_t *)data)->ti_flags = 0;
1162 case CONS_SETTERM: /* set the current terminal emulator */
1164 error = sc_init_emulator(scp, ((term_info_t *)data)->ti_name);
1165 /* FIXME: what if scp == sc_console! XXX */
1169 case GIO_SCRNMAP: /* get output translation table */
1170 bcopy(&sc->scr_map, data, sizeof(sc->scr_map));
1173 case PIO_SCRNMAP: /* set output translation table */
1174 bcopy(data, &sc->scr_map, sizeof(sc->scr_map));
1175 for (i=0; i<sizeof(sc->scr_map); i++) {
1176 sc->scr_rmap[sc->scr_map[i]] = i;
1180 case GIO_KEYMAP: /* get keyboard translation table */
1181 case PIO_KEYMAP: /* set keyboard translation table */
1182 case GIO_DEADKEYMAP: /* get accent key translation table */
1183 case PIO_DEADKEYMAP: /* set accent key translation table */
1184 case GETFKEY: /* get function key string */
1185 case SETFKEY: /* set function key string */
1186 error = kbd_ioctl(sc->kbd, cmd, data);
1187 if (error == ENOIOCTL)
1191 #ifndef SC_NO_FONT_LOADING
1193 case PIO_FONT8x8: /* set 8x8 dot font */
1194 if (!ISFONTAVAIL(sc->adp->va_flags))
1196 bcopy(data, sc->font_8, 8*256);
1197 sc->fonts_loaded |= FONT_8;
1200 * Always use the font page #0. XXX
1201 * Don't load if the current font size is not 8x8.
1203 if (ISTEXTSC(sc->cur_scp) && (sc->cur_scp->font_size < 14))
1204 sc_load_font(sc->cur_scp, 0, 8, sc->font_8, 0, 256);
1207 case GIO_FONT8x8: /* get 8x8 dot font */
1208 if (!ISFONTAVAIL(sc->adp->va_flags))
1210 if (sc->fonts_loaded & FONT_8) {
1211 bcopy(sc->font_8, data, 8*256);
1217 case PIO_FONT8x14: /* set 8x14 dot font */
1218 if (!ISFONTAVAIL(sc->adp->va_flags))
1220 bcopy(data, sc->font_14, 14*256);
1221 sc->fonts_loaded |= FONT_14;
1224 * Always use the font page #0. XXX
1225 * Don't load if the current font size is not 8x14.
1227 if (ISTEXTSC(sc->cur_scp)
1228 && (sc->cur_scp->font_size >= 14)
1229 && (sc->cur_scp->font_size < 16))
1230 sc_load_font(sc->cur_scp, 0, 14, sc->font_14, 0, 256);
1233 case GIO_FONT8x14: /* get 8x14 dot font */
1234 if (!ISFONTAVAIL(sc->adp->va_flags))
1236 if (sc->fonts_loaded & FONT_14) {
1237 bcopy(sc->font_14, data, 14*256);
1243 case PIO_FONT8x16: /* set 8x16 dot font */
1244 if (!ISFONTAVAIL(sc->adp->va_flags))
1246 bcopy(data, sc->font_16, 16*256);
1247 sc->fonts_loaded |= FONT_16;
1250 * Always use the font page #0. XXX
1251 * Don't load if the current font size is not 8x16.
1253 if (ISTEXTSC(sc->cur_scp) && (sc->cur_scp->font_size >= 16))
1254 sc_load_font(sc->cur_scp, 0, 16, sc->font_16, 0, 256);
1257 case GIO_FONT8x16: /* get 8x16 dot font */
1258 if (!ISFONTAVAIL(sc->adp->va_flags))
1260 if (sc->fonts_loaded & FONT_16) {
1261 bcopy(sc->font_16, data, 16*256);
1267 #endif /* SC_NO_FONT_LOADING */
1273 error = (*linesw[tp->t_line].l_ioctl)(tp, cmd, data, flag, td);
1274 if (error != ENOIOCTL)
1276 error = ttioctl(tp, cmd, data, flag);
1277 if (error != ENOIOCTL)
1283 scstart(struct tty *tp)
1287 u_char buf[PCBURST];
1288 scr_stat *scp = SC_STAT(tp->t_dev);
1290 if (scp->status & SLKED || 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)
1315 cp->cn_pri = sc_get_cons_priority(&unit, &flags);
1317 /* a video card is always required */
1318 if (!scvidprobe(unit, flags, TRUE))
1319 cp->cn_pri = CN_DEAD;
1321 /* syscons will become console even when there is no keyboard */
1322 sckbdprobe(unit, flags, TRUE);
1324 if (cp->cn_pri == CN_DEAD)
1327 /* initialize required fields */
1328 cp->cn_dev = makedev(CDEV_MAJOR, SC_CONSOLECTL);
1329 #endif /* __i386__ */
1333 * alpha use sccnattach() rather than cnprobe()/cninit()/cnterm()
1334 * interface to install the console. Always return CN_DEAD from
1337 cp->cn_pri = CN_DEAD;
1338 #endif /* __alpha__ */
1342 sccninit(struct consdev *cp)
1348 sc_get_cons_priority(&unit, &flags);
1349 scinit(unit, flags | SC_KERNEL_CONSOLE);
1350 sc_console_unit = unit;
1351 sc_console = SC_STAT(sc_get_softc(unit, SC_KERNEL_CONSOLE)->dev[0]);
1352 #endif /* __i386__ */
1355 /* SHOULDN'T REACH HERE */
1356 #endif /* __alpha__ */
1360 sccnterm(struct consdev *cp)
1362 /* we are not the kernel console any more, release everything */
1364 if (sc_console_unit < 0)
1365 return; /* shouldn't happen */
1369 sc_clear_screen(sc_console);
1370 sccnupdate(sc_console);
1372 scterm(sc_console_unit, SC_KERNEL_CONSOLE);
1373 sc_console_unit = -1;
1375 #endif /* __i386__ */
1378 /* do nothing XXX */
1379 #endif /* __alpha__ */
1387 static struct consdev consdev;
1391 bcopy(&sc_consdev, &consdev, sizeof(sc_consdev));
1392 consdev.cn_pri = sc_get_cons_priority(&unit, &flags);
1394 /* a video card is always required */
1395 if (!scvidprobe(unit, flags, TRUE))
1396 consdev.cn_pri = CN_DEAD;
1398 /* alpha doesn't allow the console being without a keyboard... Why? */
1399 if (!sckbdprobe(unit, flags, TRUE))
1400 consdev.cn_pri = CN_DEAD;
1402 if (consdev.cn_pri == CN_DEAD)
1405 scinit(unit, flags | SC_KERNEL_CONSOLE);
1406 sc_console_unit = unit;
1407 sc_console = SC_STAT(sc_get_softc(unit, SC_KERNEL_CONSOLE)->dev[0]);
1408 consdev.cn_dev = makedev(CDEV_MAJOR, 0);
1412 #endif /* __alpha__ */
1415 sccnputc(dev_t dev, int c)
1418 scr_stat *scp = sc_console;
1420 #ifndef SC_NO_HISTORY
1422 #endif /* !SC_NO_HISTORY */
1425 /* assert(sc_console != NULL) */
1427 #ifndef SC_NO_HISTORY
1428 if (scp == scp->sc->cur_scp && scp->status & SLKED) {
1429 scp->status &= ~SLKED;
1430 update_kbd_state(scp, scp->status, SLKED);
1431 if (scp->status & BUFFER_SAVED) {
1432 if (!sc_hist_restore(scp))
1433 sc_remove_cutmarking(scp);
1434 scp->status &= ~BUFFER_SAVED;
1435 scp->status |= CURSOR_ENABLED;
1436 sc_draw_cursor_image(scp);
1438 tp = VIRTUAL_TTY(scp->sc, scp->index);
1442 #endif /* !SC_NO_HISTORY */
1445 if (kernel_console_ts != NULL)
1446 scp->ts = kernel_console_ts;
1448 sc_puts(scp, buf, 1);
1451 s = spltty(); /* block sckbdevent and scrn_timer */
1459 return sccngetch(0);
1463 sccncheckc(dev_t dev)
1465 return sccngetch(SCGETC_NONBLOCK);
1469 sccndbctl(dev_t dev, int on)
1471 /* assert(sc_console_unit >= 0) */
1472 /* try to switch to the kernel console screen */
1473 if (on && debugger == 0) {
1475 * TRY to make sure the screen saver is stopped,
1476 * and the screen is updated before switching to
1481 && sc_console->sc->cur_scp->smode.mode == VT_AUTO
1482 && sc_console->smode.mode == VT_AUTO) {
1483 sc_console->sc->cur_scp->status |= MOUSE_HIDDEN;
1484 sc_switch_scr(sc_console->sc, sc_console->index);
1494 sccngetch(int flags)
1496 static struct fkeytab fkey;
1501 int s = spltty(); /* block sckbdevent and scrn_timer while we poll */
1504 /* assert(sc_console != NULL) */
1507 * Stop the screen saver and update the screen if necessary.
1508 * What if we have been running in the screen saver code... XXX
1510 sc_touch_scrn_saver();
1511 scp = sc_console->sc->cur_scp; /* XXX */
1514 if (fkeycp < fkey.len) {
1516 return fkey.str[fkeycp++];
1519 if (scp->sc->kbd == NULL) {
1525 * Make sure the keyboard is accessible even when the kbd device
1526 * driver is disabled.
1528 kbd_enable(scp->sc->kbd);
1530 /* we shall always use the keyboard in the XLATE mode here */
1531 cur_mode = scp->kbd_mode;
1532 scp->kbd_mode = K_XLATE;
1533 kbd_ioctl(scp->sc->kbd, KDSKBMODE, (caddr_t)&scp->kbd_mode);
1535 kbd_poll(scp->sc->kbd, TRUE);
1536 c = scgetc(scp->sc, SCGETC_CN | flags);
1537 kbd_poll(scp->sc->kbd, FALSE);
1539 scp->kbd_mode = cur_mode;
1540 kbd_ioctl(scp->sc->kbd, KDSKBMODE, (caddr_t)&scp->kbd_mode);
1541 kbd_disable(scp->sc->kbd);
1544 switch (KEYFLAGS(c)) {
1545 case 0: /* normal char */
1547 case FKEY: /* function key */
1548 p = kbd_get_fkeystr(scp->sc->kbd, KEYCHAR(c), (size_t *)&fkeycp);
1550 if ((p != NULL) && (fkey.len > 0)) {
1551 bcopy(p, fkey.str, fkey.len);
1565 sccnupdate(scr_stat *scp)
1567 /* this is a cut-down version of scrn_timer()... */
1569 if (scp->sc->font_loading_in_progress || scp->sc->videoio_in_progress)
1572 if (debugger > 0 || panicstr || shutdown_in_progress) {
1573 sc_touch_scrn_saver();
1574 } else if (scp != scp->sc->cur_scp) {
1578 if (!run_scrn_saver)
1579 scp->sc->flags &= ~SC_SCRN_IDLE;
1581 if ((saver_mode != CONS_LKM_SAVER) || !(scp->sc->flags & SC_SCRN_IDLE))
1582 if (scp->sc->flags & SC_SCRN_BLANKED)
1583 stop_scrn_saver(scp->sc, current_saver);
1584 #endif /* NSPLASH */
1586 if (scp != scp->sc->cur_scp || scp->sc->blink_in_progress
1587 || scp->sc->switch_in_progress)
1590 * FIXME: unlike scrn_timer(), we call scrn_update() from here even
1591 * when write_in_progress is non-zero. XXX
1594 if (!ISGRAPHSC(scp) && !(scp->sc->flags & SC_SCRN_BLANKED))
1595 scrn_update(scp, TRUE);
1599 scrn_timer(void *arg)
1601 static int kbd_interval = 0;
1608 again = (arg != NULL);
1610 sc = (sc_softc_t *)arg;
1611 else if (sc_console != NULL)
1612 sc = sc_console->sc;
1616 /* don't do anything when we are performing some I/O operations */
1617 if (sc->font_loading_in_progress || sc->videoio_in_progress) {
1619 timeout(scrn_timer, sc, hz / 10);
1624 if ((sc->kbd == NULL) && (sc->config & SC_AUTODETECT_KBD)) {
1625 /* try to allocate a keyboard automatically */
1626 if (++kbd_interval >= 25) {
1627 sc->keyboard = kbd_allocate("*", -1, (void *)&sc->keyboard,
1629 if (sc->keyboard >= 0) {
1630 sc->kbd = kbd_get_keyboard(sc->keyboard);
1631 kbd_ioctl(sc->kbd, KDSKBMODE,
1632 (caddr_t)&sc->cur_scp->kbd_mode);
1633 update_kbd_state(sc->cur_scp, sc->cur_scp->status,
1640 /* find the vty to update */
1643 /* should we stop the screen saver? */
1644 getmicrouptime(&tv);
1645 if (debugger > 0 || panicstr || shutdown_in_progress)
1646 sc_touch_scrn_saver();
1647 if (run_scrn_saver) {
1648 if (tv.tv_sec > sc->scrn_time_stamp + scrn_blank_time)
1649 sc->flags |= SC_SCRN_IDLE;
1651 sc->flags &= ~SC_SCRN_IDLE;
1653 sc->scrn_time_stamp = tv.tv_sec;
1654 sc->flags &= ~SC_SCRN_IDLE;
1655 if (scrn_blank_time > 0)
1656 run_scrn_saver = TRUE;
1659 if ((saver_mode != CONS_LKM_SAVER) || !(sc->flags & SC_SCRN_IDLE))
1660 if (sc->flags & SC_SCRN_BLANKED)
1661 stop_scrn_saver(sc, current_saver);
1662 #endif /* NSPLASH */
1664 /* should we just return ? */
1665 if (sc->blink_in_progress || sc->switch_in_progress
1666 || sc->write_in_progress) {
1668 timeout(scrn_timer, sc, hz / 10);
1673 /* Update the screen */
1674 scp = sc->cur_scp; /* cur_scp may have changed... */
1675 if (!ISGRAPHSC(scp) && !(sc->flags & SC_SCRN_BLANKED))
1676 scrn_update(scp, TRUE);
1679 /* should we activate the screen saver? */
1680 if ((saver_mode == CONS_LKM_SAVER) && (sc->flags & SC_SCRN_IDLE))
1681 if (!ISGRAPHSC(scp) || (sc->flags & SC_SCRN_BLANKED))
1682 (*current_saver)(sc, TRUE);
1683 #endif /* NSPLASH */
1686 timeout(scrn_timer, sc, hz / 25);
1691 and_region(int *s1, int *e1, int s2, int e2)
1693 if (*e1 < s2 || e2 < *s1)
1695 *s1 = imax(*s1, s2);
1696 *e1 = imin(*e1, e2);
1701 scrn_update(scr_stat *scp, int show_cursor)
1708 /* assert(scp == scp->sc->cur_scp) */
1710 ++scp->sc->videoio_in_progress;
1712 #ifndef SC_NO_CUTPASTE
1713 /* remove the previous mouse pointer image if necessary */
1714 if (scp->status & MOUSE_VISIBLE) {
1716 e = scp->mouse_pos + scp->xsize + 1;
1717 if ((scp->status & (MOUSE_MOVED | MOUSE_HIDDEN))
1718 || and_region(&s, &e, scp->start, scp->end)
1719 || ((scp->status & CURSOR_ENABLED) &&
1720 (scp->cursor_pos != scp->cursor_oldpos) &&
1721 (and_region(&s, &e, scp->cursor_pos, scp->cursor_pos)
1722 || and_region(&s, &e, scp->cursor_oldpos, scp->cursor_oldpos)))) {
1723 sc_remove_mouse_image(scp);
1724 if (scp->end >= scp->xsize*scp->ysize)
1725 scp->end = scp->xsize*scp->ysize - 1;
1728 #endif /* !SC_NO_CUTPASTE */
1732 if (scp->end >= scp->xsize*scp->ysize) {
1733 printf("scrn_update(): scp->end %d > size_of_screen!!\n", scp->end);
1734 scp->end = scp->xsize*scp->ysize - 1;
1736 if (scp->start < 0) {
1737 printf("scrn_update(): scp->start %d < 0\n", scp->start);
1742 /* update screen image */
1743 if (scp->start <= scp->end) {
1744 if (scp->mouse_cut_end >= 0) {
1745 /* there is a marked region for cut & paste */
1746 if (scp->mouse_cut_start <= scp->mouse_cut_end) {
1747 start = scp->mouse_cut_start;
1748 end = scp->mouse_cut_end;
1750 start = scp->mouse_cut_end;
1751 end = scp->mouse_cut_start - 1;
1755 /* does the cut-mark region overlap with the update region? */
1756 if (and_region(&s, &e, scp->start, scp->end)) {
1757 (*scp->rndr->draw)(scp, s, e - s + 1, TRUE);
1760 if (and_region(&s, &e, scp->start, scp->end))
1761 (*scp->rndr->draw)(scp, s, e - s + 1, FALSE);
1763 e = scp->xsize*scp->ysize - 1;
1764 if (and_region(&s, &e, scp->start, scp->end))
1765 (*scp->rndr->draw)(scp, s, e - s + 1, FALSE);
1767 (*scp->rndr->draw)(scp, scp->start,
1768 scp->end - scp->start + 1, FALSE);
1771 (*scp->rndr->draw)(scp, scp->start,
1772 scp->end - scp->start + 1, FALSE);
1776 /* we are not to show the cursor and the mouse pointer... */
1779 scp->start = scp->xsize*scp->ysize - 1;
1780 --scp->sc->videoio_in_progress;
1784 /* update cursor image */
1785 if (scp->status & CURSOR_ENABLED) {
1788 /* did cursor move since last time ? */
1789 if (scp->cursor_pos != scp->cursor_oldpos) {
1790 /* do we need to remove old cursor image ? */
1791 if (!and_region(&s, &e, scp->cursor_oldpos, scp->cursor_oldpos))
1792 sc_remove_cursor_image(scp);
1793 sc_draw_cursor_image(scp);
1795 if (and_region(&s, &e, scp->cursor_pos, scp->cursor_pos))
1796 /* cursor didn't move, but has been overwritten */
1797 sc_draw_cursor_image(scp);
1798 else if (scp->sc->flags & SC_BLINK_CURSOR)
1799 /* if it's a blinking cursor, update it */
1800 (*scp->rndr->blink_cursor)(scp, scp->cursor_pos,
1801 sc_inside_cutmark(scp,
1806 #ifndef SC_NO_CUTPASTE
1807 /* update "pseudo" mouse pointer image */
1808 if (scp->sc->flags & SC_MOUSE_ENABLED) {
1809 if (!(scp->status & (MOUSE_VISIBLE | MOUSE_HIDDEN))) {
1810 scp->status &= ~MOUSE_MOVED;
1811 sc_draw_mouse_image(scp);
1814 #endif /* SC_NO_CUTPASTE */
1817 scp->start = scp->xsize*scp->ysize - 1;
1819 --scp->sc->videoio_in_progress;
1824 scsplash_callback(int event, void *arg)
1829 sc = (sc_softc_t *)arg;
1833 if (add_scrn_saver(scsplash_saver) == 0) {
1834 sc->flags &= ~SC_SAVER_FAILED;
1835 run_scrn_saver = TRUE;
1836 if (cold && !(boothowto & (RB_VERBOSE | RB_CONFIG))) {
1837 scsplash_stick(TRUE);
1838 (*current_saver)(sc, TRUE);
1844 if (current_saver == scsplash_saver) {
1845 scsplash_stick(FALSE);
1846 error = remove_scrn_saver(scsplash_saver);
1858 scsplash_saver(sc_softc_t *sc, int show)
1860 static int busy = FALSE;
1869 if (!(sc->flags & SC_SAVER_FAILED)) {
1870 if (!(sc->flags & SC_SCRN_BLANKED))
1871 set_scrn_saver_mode(scp, -1, NULL, 0);
1872 switch (splash(sc->adp, TRUE)) {
1873 case 0: /* succeeded */
1875 case EAGAIN: /* try later */
1876 restore_scrn_saver_mode(scp, FALSE);
1877 sc_touch_scrn_saver(); /* XXX */
1880 sc->flags |= SC_SAVER_FAILED;
1881 scsplash_stick(FALSE);
1882 restore_scrn_saver_mode(scp, TRUE);
1883 printf("scsplash_saver(): failed to put up the image\n");
1887 } else if (!sticky_splash) {
1888 if ((sc->flags & SC_SCRN_BLANKED) && (splash(sc->adp, FALSE) == 0))
1889 restore_scrn_saver_mode(scp, TRUE);
1895 add_scrn_saver(void (*this_saver)(sc_softc_t *, int))
1900 if (current_saver != none_saver) {
1901 error = remove_scrn_saver(current_saver);
1906 if (current_saver != none_saver)
1909 run_scrn_saver = FALSE;
1910 saver_mode = CONS_LKM_SAVER;
1911 current_saver = this_saver;
1916 remove_scrn_saver(void (*this_saver)(sc_softc_t *, int))
1918 if (current_saver != this_saver)
1923 * In order to prevent `current_saver' from being called by
1924 * the timeout routine `scrn_timer()' while we manipulate
1925 * the saver list, we shall set `current_saver' to `none_saver'
1926 * before stopping the current saver, rather than blocking by `splXX()'.
1928 current_saver = none_saver;
1930 stop_scrn_saver(this_saver);
1933 /* unblank all blanked screens */
1934 wait_scrn_saver_stop(NULL);
1938 current_saver = none_saver;
1943 set_scrn_saver_mode(scr_stat *scp, int mode, u_char *pal, int border)
1947 /* assert(scp == scp->sc->cur_scp) */
1949 if (!ISGRAPHSC(scp))
1950 sc_remove_cursor_image(scp);
1951 scp->splash_save_mode = scp->mode;
1952 scp->splash_save_status = scp->status & (GRAPHICS_MODE | PIXEL_MODE);
1953 scp->status &= ~(GRAPHICS_MODE | PIXEL_MODE);
1954 scp->status |= (UNKNOWN_MODE | SAVER_RUNNING);
1955 scp->sc->flags |= SC_SCRN_BLANKED;
1961 if (set_mode(scp) == 0) {
1962 if (scp->sc->adp->va_info.vi_flags & V_INFO_GRAPHICS)
1963 scp->status |= GRAPHICS_MODE;
1964 #ifndef SC_NO_PALETTE_LOADING
1966 load_palette(scp->sc->adp, pal);
1968 sc_set_border(scp, border);
1972 scp->mode = scp->splash_save_mode;
1973 scp->status &= ~(UNKNOWN_MODE | SAVER_RUNNING);
1974 scp->status |= scp->splash_save_status;
1981 restore_scrn_saver_mode(scr_stat *scp, int changemode)
1987 /* assert(scp == scp->sc->cur_scp) */
1990 status = scp->status;
1991 scp->mode = scp->splash_save_mode;
1992 scp->status &= ~(UNKNOWN_MODE | SAVER_RUNNING);
1993 scp->status |= scp->splash_save_status;
1994 scp->sc->flags &= ~SC_SCRN_BLANKED;
1996 if (!ISGRAPHSC(scp))
1997 sc_draw_cursor_image(scp);
2002 if (set_mode(scp) == 0) {
2003 #ifndef SC_NO_PALETTE_LOADING
2004 load_palette(scp->sc->adp, scp->sc->palette);
2011 scp->status = status;
2018 stop_scrn_saver(sc_softc_t *sc, void (*saver)(sc_softc_t *, int))
2020 (*saver)(sc, FALSE);
2021 run_scrn_saver = FALSE;
2022 /* the screen saver may have chosen not to stop after all... */
2023 if (sc->flags & SC_SCRN_BLANKED)
2026 mark_all(sc->cur_scp);
2027 if (sc->delayed_next_scr)
2028 sc_switch_scr(sc, sc->delayed_next_scr - 1);
2029 wakeup((caddr_t)&scrn_blanked);
2033 wait_scrn_saver_stop(sc_softc_t *sc)
2037 while (scrn_blanked > 0) {
2038 run_scrn_saver = FALSE;
2039 if (sc && !(sc->flags & SC_SCRN_BLANKED)) {
2043 error = tsleep((caddr_t)&scrn_blanked, PZERO | PCATCH, "scrsav", 0);
2044 if ((error != 0) && (error != ERESTART))
2047 run_scrn_saver = FALSE;
2050 #endif /* NSPLASH */
2053 sc_touch_scrn_saver(void)
2055 scsplash_stick(FALSE);
2056 run_scrn_saver = FALSE;
2060 sc_switch_scr(sc_softc_t *sc, u_int next_scr)
2066 DPRINTF(5, ("sc0: sc_switch_scr() %d ", next_scr + 1));
2068 /* prevent switch if previously requested */
2069 if (sc->flags & SC_SCRN_VTYLOCK) {
2070 sc_bell(sc->cur_scp, sc->cur_scp->bell_pitch,
2071 sc->cur_scp->bell_duration);
2075 /* delay switch if the screen is blanked or being updated */
2076 if ((sc->flags & SC_SCRN_BLANKED) || sc->write_in_progress
2077 || sc->blink_in_progress || sc->videoio_in_progress) {
2078 sc->delayed_next_scr = next_scr + 1;
2079 sc_touch_scrn_saver();
2080 DPRINTF(5, ("switch delayed\n"));
2085 cur_scp = sc->cur_scp;
2087 /* we are in the middle of the vty switching process... */
2088 if (sc->switch_in_progress
2089 && (cur_scp->smode.mode == VT_PROCESS)
2091 if (cur_scp->proc != pfind(cur_scp->pid)) {
2093 * The controlling process has died!!. Do some clean up.
2094 * NOTE:`cur_scp->proc' and `cur_scp->smode.mode'
2095 * are not reset here yet; they will be cleared later.
2097 DPRINTF(5, ("cur_scp controlling process %d died, ",
2099 if (cur_scp->status & SWITCH_WAIT_REL) {
2101 * Force the previous switch to finish, but return now
2104 DPRINTF(5, ("reset WAIT_REL, "));
2105 finish_vt_rel(cur_scp, TRUE, &s);
2107 DPRINTF(5, ("finishing previous switch\n"));
2109 } else if (cur_scp->status & SWITCH_WAIT_ACQ) {
2110 /* let's assume screen switch has been completed. */
2111 DPRINTF(5, ("reset WAIT_ACQ, "));
2112 finish_vt_acq(cur_scp);
2115 * We are in between screen release and acquisition, and
2116 * reached here via scgetc() or scrn_timer() which has
2117 * interrupted exchange_scr(). Don't do anything stupid.
2119 DPRINTF(5, ("waiting nothing, "));
2123 * The controlling process is alive, but not responding...
2124 * It is either buggy or it may be just taking time.
2125 * The following code is a gross kludge to cope with this
2126 * problem for which there is no clean solution. XXX
2128 if (cur_scp->status & SWITCH_WAIT_REL) {
2129 switch (sc->switch_in_progress++) {
2133 DPRINTF(5, ("sending relsig again, "));
2134 signal_vt_rel(cur_scp);
2141 * Act as if the controlling program returned
2144 DPRINTF(5, ("force reset WAIT_REL, "));
2145 finish_vt_rel(cur_scp, FALSE, &s);
2147 DPRINTF(5, ("act as if VT_FALSE was seen\n"));
2150 } else if (cur_scp->status & SWITCH_WAIT_ACQ) {
2151 switch (sc->switch_in_progress++) {
2155 DPRINTF(5, ("sending acqsig again, "));
2156 signal_vt_acq(cur_scp);
2162 /* clear the flag and finish the previous switch */
2163 DPRINTF(5, ("force reset WAIT_ACQ, "));
2164 finish_vt_acq(cur_scp);
2172 * Return error if an invalid argument is given, or vty switch
2173 * is still in progress.
2175 if ((next_scr < sc->first_vty) || (next_scr >= sc->first_vty + sc->vtys)
2176 || sc->switch_in_progress) {
2178 sc_bell(cur_scp, bios_value.bell_pitch, BELL_DURATION);
2179 DPRINTF(5, ("error 1\n"));
2184 * Don't allow switching away from the graphics mode vty
2185 * if the switch mode is VT_AUTO, unless the next vty is the same
2186 * as the current or the current vty has been closed (but showing).
2188 tp = VIRTUAL_TTY(sc, cur_scp->index);
2189 if ((cur_scp->index != next_scr)
2191 && (cur_scp->smode.mode == VT_AUTO)
2192 && ISGRAPHSC(cur_scp)) {
2194 sc_bell(cur_scp, bios_value.bell_pitch, BELL_DURATION);
2195 DPRINTF(5, ("error, graphics mode\n"));
2200 * Is the wanted vty open? Don't allow switching to a closed vty.
2201 * If we are in DDB, don't switch to a vty in the VT_PROCESS mode.
2202 * Note that we always allow the user to switch to the kernel
2203 * console even if it is closed.
2205 if ((sc_console == NULL) || (next_scr != sc_console->index)) {
2206 tp = VIRTUAL_TTY(sc, next_scr);
2207 if (!ISTTYOPEN(tp)) {
2209 sc_bell(cur_scp, bios_value.bell_pitch, BELL_DURATION);
2210 DPRINTF(5, ("error 2, requested vty isn't open!\n"));
2213 if ((debugger > 0) && (SC_STAT(tp->t_dev)->smode.mode == VT_PROCESS)) {
2215 DPRINTF(5, ("error 3, requested vty is in the VT_PROCESS mode\n"));
2220 /* this is the start of vty switching process... */
2221 ++sc->switch_in_progress;
2222 sc->delayed_next_scr = 0;
2223 sc->old_scp = cur_scp;
2224 sc->new_scp = SC_STAT(SC_DEV(sc, next_scr));
2225 if (sc->new_scp == sc->old_scp) {
2226 sc->switch_in_progress = 0;
2227 wakeup((caddr_t)&sc->new_scp->smode);
2229 DPRINTF(5, ("switch done (new == old)\n"));
2233 /* has controlling process died? */
2234 vt_proc_alive(sc->old_scp);
2235 vt_proc_alive(sc->new_scp);
2237 /* wait for the controlling process to release the screen, if necessary */
2238 if (signal_vt_rel(sc->old_scp)) {
2243 /* go set up the new vty screen */
2248 /* wake up processes waiting for this vty */
2249 wakeup((caddr_t)&sc->cur_scp->smode);
2251 /* wait for the controlling process to acknowledge, if necessary */
2252 if (signal_vt_acq(sc->cur_scp)) {
2257 sc->switch_in_progress = 0;
2258 if (sc->unit == sc_console_unit)
2259 cons_unavail = FALSE;
2261 DPRINTF(5, ("switch done\n"));
2267 do_switch_scr(sc_softc_t *sc, int s)
2269 vt_proc_alive(sc->new_scp);
2274 /* sc->cur_scp == sc->new_scp */
2275 wakeup((caddr_t)&sc->cur_scp->smode);
2277 /* wait for the controlling process to acknowledge, if necessary */
2278 if (!signal_vt_acq(sc->cur_scp)) {
2279 sc->switch_in_progress = 0;
2280 if (sc->unit == sc_console_unit)
2281 cons_unavail = FALSE;
2288 vt_proc_alive(scr_stat *scp)
2291 if (scp->proc == pfind(scp->pid))
2294 scp->smode.mode = VT_AUTO;
2295 DPRINTF(5, ("vt controlling process %d died\n", scp->pid));
2301 signal_vt_rel(scr_stat *scp)
2303 if (scp->smode.mode != VT_PROCESS)
2305 scp->status |= SWITCH_WAIT_REL;
2306 psignal(scp->proc, scp->smode.relsig);
2307 DPRINTF(5, ("sending relsig to %d\n", scp->pid));
2312 signal_vt_acq(scr_stat *scp)
2314 if (scp->smode.mode != VT_PROCESS)
2316 if (scp->sc->unit == sc_console_unit)
2317 cons_unavail = TRUE;
2318 scp->status |= SWITCH_WAIT_ACQ;
2319 psignal(scp->proc, scp->smode.acqsig);
2320 DPRINTF(5, ("sending acqsig to %d\n", scp->pid));
2325 finish_vt_rel(scr_stat *scp, int release, int *s)
2327 if (scp == scp->sc->old_scp && scp->status & SWITCH_WAIT_REL) {
2328 scp->status &= ~SWITCH_WAIT_REL;
2330 *s = do_switch_scr(scp->sc, *s);
2332 scp->sc->switch_in_progress = 0;
2339 finish_vt_acq(scr_stat *scp)
2341 if (scp == scp->sc->new_scp && scp->status & SWITCH_WAIT_ACQ) {
2342 scp->status &= ~SWITCH_WAIT_ACQ;
2343 scp->sc->switch_in_progress = 0;
2350 exchange_scr(sc_softc_t *sc)
2354 /* save the current state of video and keyboard */
2355 sc_move_cursor(sc->old_scp, sc->old_scp->xpos, sc->old_scp->ypos);
2356 if (!ISGRAPHSC(sc->old_scp))
2357 sc_remove_cursor_image(sc->old_scp);
2358 if (sc->old_scp->kbd_mode == K_XLATE)
2359 save_kbd_state(sc->old_scp);
2361 /* set up the video for the new screen */
2362 scp = sc->cur_scp = sc->new_scp;
2363 if (sc->old_scp->mode != scp->mode || ISUNKNOWNSC(sc->old_scp))
2366 sc_vtb_init(&scp->scr, VTB_FRAMEBUFFER, scp->xsize, scp->ysize,
2367 (void *)sc->adp->va_window, FALSE);
2368 scp->status |= MOUSE_HIDDEN;
2369 sc_move_cursor(scp, scp->xpos, scp->ypos);
2370 if (!ISGRAPHSC(scp))
2371 sc_set_cursor_image(scp);
2372 #ifndef SC_NO_PALETTE_LOADING
2373 if (ISGRAPHSC(sc->old_scp))
2374 load_palette(sc->adp, sc->palette);
2376 sc_set_border(scp, scp->border);
2378 /* set up the keyboard for the new screen */
2379 if (sc->old_scp->kbd_mode != scp->kbd_mode)
2380 kbd_ioctl(sc->kbd, KDSKBMODE, (caddr_t)&scp->kbd_mode);
2381 update_kbd_state(scp, scp->status, LOCK_MASK);
2387 sc_puts(scr_stat *scp, u_char *buf, int len)
2390 /* make screensaver happy */
2391 if (!sticky_splash && scp == scp->sc->cur_scp)
2392 run_scrn_saver = FALSE;
2396 (*scp->tsw->te_puts)(scp, buf, len);
2398 if (scp->sc->delayed_next_scr)
2399 sc_switch_scr(scp->sc, scp->sc->delayed_next_scr - 1);
2403 sc_draw_cursor_image(scr_stat *scp)
2405 /* assert(scp == scp->sc->cur_scp); */
2406 ++scp->sc->videoio_in_progress;
2407 (*scp->rndr->draw_cursor)(scp, scp->cursor_pos,
2408 scp->sc->flags & SC_BLINK_CURSOR, TRUE,
2409 sc_inside_cutmark(scp, scp->cursor_pos));
2410 scp->cursor_oldpos = scp->cursor_pos;
2411 --scp->sc->videoio_in_progress;
2415 sc_remove_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_oldpos,
2420 scp->sc->flags & SC_BLINK_CURSOR, FALSE,
2421 sc_inside_cutmark(scp, scp->cursor_oldpos));
2422 --scp->sc->videoio_in_progress;
2426 update_cursor_image(scr_stat *scp)
2430 if (scp->sc->flags & SC_CHAR_CURSOR) {
2431 scp->cursor_base = imax(0, scp->sc->cursor_base);
2432 scp->cursor_height = imin(scp->sc->cursor_height, scp->font_size);
2434 scp->cursor_base = 0;
2435 scp->cursor_height = scp->font_size;
2437 blink = scp->sc->flags & SC_BLINK_CURSOR;
2439 /* assert(scp == scp->sc->cur_scp); */
2440 ++scp->sc->videoio_in_progress;
2441 (*scp->rndr->draw_cursor)(scp, scp->cursor_oldpos, blink, FALSE,
2442 sc_inside_cutmark(scp, scp->cursor_pos));
2443 (*scp->rndr->set_cursor)(scp, scp->cursor_base, scp->cursor_height, blink);
2444 (*scp->rndr->draw_cursor)(scp, scp->cursor_pos, blink, TRUE,
2445 sc_inside_cutmark(scp, scp->cursor_pos));
2446 --scp->sc->videoio_in_progress;
2450 sc_set_cursor_image(scr_stat *scp)
2452 if (scp->sc->flags & SC_CHAR_CURSOR) {
2453 scp->cursor_base = imax(0, scp->sc->cursor_base);
2454 scp->cursor_height = imin(scp->sc->cursor_height, scp->font_size);
2456 scp->cursor_base = 0;
2457 scp->cursor_height = scp->font_size;
2460 /* assert(scp == scp->sc->cur_scp); */
2461 ++scp->sc->videoio_in_progress;
2462 (*scp->rndr->set_cursor)(scp, scp->cursor_base, scp->cursor_height,
2463 scp->sc->flags & SC_BLINK_CURSOR);
2464 --scp->sc->videoio_in_progress;
2468 scinit(int unit, int flags)
2471 * When syscons is being initialized as the kernel console, malloc()
2472 * is not yet functional, because various kernel structures has not been
2473 * fully initialized yet. Therefore, we need to declare the following
2474 * static buffers for the console. This is less than ideal,
2475 * but is necessry evil for the time being. XXX
2477 static scr_stat main_console;
2478 static dev_t main_devs[MAXCONS];
2479 static struct tty main_tty;
2480 static u_short sc_buffer[ROW*COL]; /* XXX */
2481 #ifndef SC_NO_FONT_LOADING
2482 static u_char font_8[256*8];
2483 static u_char font_14[256*14];
2484 static u_char font_16[256*16];
2489 video_adapter_t *adp;
2494 /* one time initialization */
2495 if (init_done == COLD)
2496 sc_get_bios_values(&bios_value);
2500 * Allocate resources. Even if we are being called for the second
2501 * time, we must allocate them again, because they might have
2504 sc = sc_get_softc(unit, flags & SC_KERNEL_CONSOLE);
2506 if (sc->adapter >= 0) {
2507 vid_release(sc->adp, (void *)&sc->adapter);
2511 if (sc->keyboard >= 0) {
2512 DPRINTF(5, ("sc%d: releasing kbd%d\n", unit, sc->keyboard));
2513 i = kbd_release(sc->kbd, (void *)&sc->keyboard);
2514 DPRINTF(5, ("sc%d: kbd_release returned %d\n", unit, i));
2515 if (sc->kbd != NULL) {
2516 DPRINTF(5, ("sc%d: kbd != NULL!, index:%d, unit:%d, flags:0x%x\n",
2517 unit, sc->kbd->kb_index, sc->kbd->kb_unit, sc->kbd->kb_flags));
2521 sc->adapter = vid_allocate("*", unit, (void *)&sc->adapter);
2522 sc->adp = vid_get_adapter(sc->adapter);
2523 /* assert((sc->adapter >= 0) && (sc->adp != NULL)) */
2524 sc->keyboard = kbd_allocate("*", unit, (void *)&sc->keyboard,
2526 DPRINTF(1, ("sc%d: keyboard %d\n", unit, sc->keyboard));
2527 sc->kbd = kbd_get_keyboard(sc->keyboard);
2528 if (sc->kbd != NULL) {
2529 DPRINTF(1, ("sc%d: kbd index:%d, unit:%d, flags:0x%x\n",
2530 unit, sc->kbd->kb_index, sc->kbd->kb_unit, sc->kbd->kb_flags));
2533 if (!(sc->flags & SC_INIT_DONE) || (adp != sc->adp)) {
2535 sc->initial_mode = sc->adp->va_initial_mode;
2537 #ifndef SC_NO_FONT_LOADING
2538 if (flags & SC_KERNEL_CONSOLE) {
2539 sc->font_8 = font_8;
2540 sc->font_14 = font_14;
2541 sc->font_16 = font_16;
2542 } else if (sc->font_8 == NULL) {
2543 /* assert(sc_malloc) */
2544 sc->font_8 = malloc(sizeof(font_8), M_DEVBUF, M_WAITOK);
2545 sc->font_14 = malloc(sizeof(font_14), M_DEVBUF, M_WAITOK);
2546 sc->font_16 = malloc(sizeof(font_16), M_DEVBUF, M_WAITOK);
2550 /* extract the hardware cursor location and hide the cursor for now */
2551 (*vidsw[sc->adapter]->read_hw_cursor)(sc->adp, &col, &row);
2552 (*vidsw[sc->adapter]->set_hw_cursor)(sc->adp, -1, -1);
2554 /* set up the first console */
2555 sc->first_vty = unit*MAXCONS;
2556 sc->vtys = MAXCONS; /* XXX: should be configurable */
2557 if (flags & SC_KERNEL_CONSOLE) {
2558 sc->dev = main_devs;
2559 sc->dev[0] = makedev(CDEV_MAJOR, unit*MAXCONS);
2560 sc->dev[0]->si_tty = &main_tty;
2561 ttyregister(&main_tty);
2562 scp = &main_console;
2563 init_scp(sc, sc->first_vty, scp);
2564 sc_vtb_init(&scp->vtb, VTB_MEMORY, scp->xsize, scp->ysize,
2565 (void *)sc_buffer, FALSE);
2566 if (sc_init_emulator(scp, SC_DFLT_TERM))
2567 sc_init_emulator(scp, "*");
2568 (*scp->tsw->te_default_attr)(scp,
2569 kernel_default.std_color,
2570 kernel_default.rev_color);
2572 /* assert(sc_malloc) */
2573 sc->dev = malloc(sizeof(dev_t)*sc->vtys, M_DEVBUF, M_WAITOK);
2574 bzero(sc->dev, sizeof(dev_t)*sc->vtys);
2575 sc->dev[0] = makedev(CDEV_MAJOR, unit*MAXCONS);
2576 sc->dev[0]->si_tty = ttymalloc(sc->dev[0]->si_tty);
2577 scp = alloc_scp(sc, sc->first_vty);
2579 SC_STAT(sc->dev[0]) = scp;
2582 /* copy screen to temporary buffer */
2583 sc_vtb_init(&scp->scr, VTB_FRAMEBUFFER, scp->xsize, scp->ysize,
2584 (void *)scp->sc->adp->va_window, FALSE);
2586 sc_vtb_copy(&scp->scr, 0, &scp->vtb, 0, scp->xsize*scp->ysize);
2588 /* move cursors to the initial positions */
2589 if (col >= scp->xsize)
2591 if (row >= scp->ysize)
2592 row = scp->ysize - 1;
2595 scp->cursor_pos = scp->cursor_oldpos = row*scp->xsize + col;
2596 if (bios_value.cursor_end < scp->font_size)
2597 sc->cursor_base = scp->font_size - bios_value.cursor_end - 1;
2599 sc->cursor_base = 0;
2600 i = bios_value.cursor_end - bios_value.cursor_start + 1;
2601 sc->cursor_height = imin(i, scp->font_size);
2602 #ifndef SC_NO_SYSMOUSE
2603 sc_mouse_move(scp, scp->xpixel/2, scp->ypixel/2);
2605 if (!ISGRAPHSC(scp)) {
2606 sc_set_cursor_image(scp);
2607 sc_draw_cursor_image(scp);
2610 /* save font and palette */
2611 #ifndef SC_NO_FONT_LOADING
2612 sc->fonts_loaded = 0;
2613 if (ISFONTAVAIL(sc->adp->va_flags)) {
2615 bcopy(dflt_font_8, sc->font_8, sizeof(dflt_font_8));
2616 bcopy(dflt_font_14, sc->font_14, sizeof(dflt_font_14));
2617 bcopy(dflt_font_16, sc->font_16, sizeof(dflt_font_16));
2618 sc->fonts_loaded = FONT_16 | FONT_14 | FONT_8;
2619 if (scp->font_size < 14) {
2620 sc_load_font(scp, 0, 8, sc->font_8, 0, 256);
2621 } else if (scp->font_size >= 16) {
2622 sc_load_font(scp, 0, 16, sc->font_16, 0, 256);
2624 sc_load_font(scp, 0, 14, sc->font_14, 0, 256);
2626 #else /* !SC_DFLT_FONT */
2627 if (scp->font_size < 14) {
2628 sc_save_font(scp, 0, 8, sc->font_8, 0, 256);
2629 sc->fonts_loaded = FONT_8;
2630 } else if (scp->font_size >= 16) {
2631 sc_save_font(scp, 0, 16, sc->font_16, 0, 256);
2632 sc->fonts_loaded = FONT_16;
2634 sc_save_font(scp, 0, 14, sc->font_14, 0, 256);
2635 sc->fonts_loaded = FONT_14;
2637 #endif /* SC_DFLT_FONT */
2638 /* FONT KLUDGE: always use the font page #0. XXX */
2639 sc_show_font(scp, 0);
2641 #endif /* !SC_NO_FONT_LOADING */
2643 #ifndef SC_NO_PALETTE_LOADING
2644 save_palette(sc->adp, sc->palette);
2648 if (!(sc->flags & SC_SPLASH_SCRN) && (flags & SC_KERNEL_CONSOLE)) {
2649 /* we are ready to put up the splash image! */
2650 splash_init(sc->adp, scsplash_callback, sc);
2651 sc->flags |= SC_SPLASH_SCRN;
2653 #endif /* NSPLASH */
2656 /* the rest is not necessary, if we have done it once */
2657 if (sc->flags & SC_INIT_DONE)
2660 /* initialize mapscrn arrays to a one to one map */
2661 for (i = 0; i < sizeof(sc->scr_map); i++)
2662 sc->scr_map[i] = sc->scr_rmap[i] = i;
2664 sc->flags |= SC_INIT_DONE;
2669 scterm(int unit, int flags)
2674 sc = sc_get_softc(unit, flags & SC_KERNEL_CONSOLE);
2676 return; /* shouldn't happen */
2679 /* this console is no longer available for the splash screen */
2680 if (sc->flags & SC_SPLASH_SCRN) {
2681 splash_term(sc->adp);
2682 sc->flags &= ~SC_SPLASH_SCRN;
2684 #endif /* NSPLASH */
2687 /* move the hardware cursor to the upper-left corner */
2688 (*vidsw[sc->adapter]->set_hw_cursor)(sc->adp, 0, 0);
2691 /* release the keyboard and the video card */
2692 if (sc->keyboard >= 0)
2693 kbd_release(sc->kbd, &sc->keyboard);
2694 if (sc->adapter >= 0)
2695 vid_release(sc->adp, &sc->adapter);
2697 /* stop the terminal emulator, if any */
2698 scp = SC_STAT(sc->dev[0]);
2700 (*scp->tsw->te_term)(scp, &scp->ts);
2701 if (scp->ts != NULL)
2702 free(scp->ts, M_DEVBUF);
2704 /* clear the structure */
2705 if (!(flags & SC_KERNEL_CONSOLE)) {
2706 /* XXX: We need delete_dev() for this */
2707 free(sc->dev, M_DEVBUF);
2709 /* XXX: We need a ttyunregister for this */
2710 free(sc->tty, M_DEVBUF);
2712 #ifndef SC_NO_FONT_LOADING
2713 free(sc->font_8, M_DEVBUF);
2714 free(sc->font_14, M_DEVBUF);
2715 free(sc->font_16, M_DEVBUF);
2717 /* XXX vtb, history */
2719 bzero(sc, sizeof(*sc));
2726 scshutdown(void *arg, int howto)
2728 /* assert(sc_console != NULL) */
2730 sc_touch_scrn_saver();
2731 if (!cold && sc_console
2732 && sc_console->sc->cur_scp->smode.mode == VT_AUTO
2733 && sc_console->smode.mode == VT_AUTO)
2734 sc_switch_scr(sc_console->sc, sc_console->index);
2735 shutdown_in_progress = TRUE;
2739 sc_clean_up(scr_stat *scp)
2743 #endif /* NSPLASH */
2745 if (scp->sc->flags & SC_SCRN_BLANKED) {
2746 sc_touch_scrn_saver();
2748 if ((error = wait_scrn_saver_stop(scp->sc)))
2750 #endif /* NSPLASH */
2752 scp->status |= MOUSE_HIDDEN;
2753 sc_remove_mouse_image(scp);
2754 sc_remove_cutmarking(scp);
2759 sc_alloc_scr_buffer(scr_stat *scp, int wait, int discard)
2765 sc_vtb_init(&new, VTB_MEMORY, scp->xsize, scp->ysize, NULL, wait);
2766 if (!discard && (old.vtb_flags & VTB_VALID)) {
2767 /* retain the current cursor position and buffer contants */
2768 scp->cursor_oldpos = scp->cursor_pos;
2770 * This works only if the old buffer has the same size as or larger
2771 * than the new one. XXX
2773 sc_vtb_copy(&old, 0, &new, 0, scp->xsize*scp->ysize);
2777 sc_vtb_destroy(&old);
2780 #ifndef SC_NO_SYSMOUSE
2781 /* move the mouse cursor at the center of the screen */
2782 sc_mouse_move(scp, scp->xpixel / 2, scp->ypixel / 2);
2787 *alloc_scp(sc_softc_t *sc, int vty)
2791 /* assert(sc_malloc) */
2793 scp = (scr_stat *)malloc(sizeof(scr_stat), M_DEVBUF, M_WAITOK);
2794 init_scp(sc, vty, scp);
2796 sc_alloc_scr_buffer(scp, TRUE, TRUE);
2797 if (sc_init_emulator(scp, SC_DFLT_TERM))
2798 sc_init_emulator(scp, "*");
2800 #ifndef SC_NO_CUTPASTE
2801 sc_alloc_cut_buffer(scp, TRUE);
2804 #ifndef SC_NO_HISTORY
2805 sc_alloc_history_buffer(scp, 0, 0, TRUE);
2812 init_scp(sc_softc_t *sc, int vty, scr_stat *scp)
2816 bzero(scp, sizeof(*scp));
2821 scp->mode = sc->initial_mode;
2822 (*vidsw[sc->adapter]->get_info)(sc->adp, scp->mode, &info);
2823 if (info.vi_flags & V_INFO_GRAPHICS) {
2824 scp->status |= GRAPHICS_MODE;
2825 scp->xpixel = info.vi_width;
2826 scp->ypixel = info.vi_height;
2827 scp->xsize = info.vi_width/8;
2828 scp->ysize = info.vi_height/info.vi_cheight;
2832 scp->xsize = info.vi_width;
2833 scp->ysize = info.vi_height;
2834 scp->xpixel = scp->xsize*8;
2835 scp->ypixel = scp->ysize*info.vi_cheight;
2836 if (info.vi_cheight < 14) {
2838 #ifndef SC_NO_FONT_LOADING
2839 scp->font = sc->font_8;
2843 } else if (info.vi_cheight >= 16) {
2844 scp->font_size = 16;
2845 #ifndef SC_NO_FONT_LOADING
2846 scp->font = sc->font_16;
2851 scp->font_size = 14;
2852 #ifndef SC_NO_FONT_LOADING
2853 scp->font = sc->font_14;
2859 sc_vtb_init(&scp->vtb, VTB_MEMORY, 0, 0, NULL, FALSE);
2860 sc_vtb_init(&scp->scr, VTB_FRAMEBUFFER, 0, 0, NULL, FALSE);
2861 scp->xoff = scp->yoff = 0;
2862 scp->xpos = scp->ypos = 0;
2863 scp->start = scp->xsize * scp->ysize - 1;
2868 scp->border = BG_BLACK;
2869 scp->cursor_base = sc->cursor_base;
2870 scp->cursor_height = imin(sc->cursor_height, scp->font_size);
2871 scp->mouse_cut_start = scp->xsize*scp->ysize;
2872 scp->mouse_cut_end = -1;
2873 scp->mouse_signal = 0;
2875 scp->mouse_proc = NULL;
2876 scp->kbd_mode = K_XLATE;
2877 scp->bell_pitch = bios_value.bell_pitch;
2878 scp->bell_duration = BELL_DURATION;
2879 scp->status |= (bios_value.shift_state & NLKED);
2880 scp->status |= CURSOR_ENABLED | MOUSE_HIDDEN;
2883 scp->smode.mode = VT_AUTO;
2884 scp->history = NULL;
2885 scp->history_pos = 0;
2886 scp->history_size = 0;
2890 sc_init_emulator(scr_stat *scp, char *name)
2897 if (name == NULL) /* if no name is given, use the current emulator */
2899 else /* ...otherwise find the named emulator */
2900 sw = sc_term_match(name);
2905 if (strcmp(sw->te_renderer, "*") != 0) {
2906 rndr = sc_render_match(scp, sw->te_renderer,
2907 scp->status & (GRAPHICS_MODE | PIXEL_MODE));
2910 rndr = sc_render_match(scp, scp->sc->adp->va_name,
2911 scp->status & (GRAPHICS_MODE | PIXEL_MODE));
2916 if (sw == scp->tsw) {
2917 error = (*sw->te_init)(scp, &scp->ts, SC_TE_WARM_INIT);
2919 sc_clear_screen(scp);
2920 /* assert(error == 0); */
2924 if (sc_malloc && (sw->te_size > 0))
2925 p = malloc(sw->te_size, M_DEVBUF, M_NOWAIT);
2928 error = (*sw->te_init)(scp, &p, SC_TE_COLD_INIT);
2933 (*scp->tsw->te_term)(scp, &scp->ts);
2934 if (scp->ts != NULL)
2935 free(scp->ts, M_DEVBUF);
2941 (*sw->te_default_attr)(scp, user_default.std_color, user_default.rev_color);
2942 sc_clear_screen(scp);
2948 * scgetc(flags) - get character from keyboard.
2949 * If flags & SCGETC_CN, then avoid harmful side effects.
2950 * If flags & SCGETC_NONBLOCK, then wait until a key is pressed, else
2951 * return NOKEY if there is nothing there.
2954 scgetc(sc_softc_t *sc, u_int flags)
2957 #ifndef SC_NO_HISTORY
2965 if (sc->kbd == NULL)
2970 /* I don't like this, but... XXX */
2971 if (flags & SCGETC_CN)
2972 sccnupdate(sc->cur_scp);
2975 /* first see if there is something in the keyboard port */
2977 c = kbd_read_char(sc->kbd, !(flags & SCGETC_NONBLOCK));
2979 if (!(flags & SCGETC_CN))
2980 sc_bell(scp, bios_value.bell_pitch, BELL_DURATION);
2981 } else if (c == NOKEY)
2987 /* make screensaver happy */
2989 sc_touch_scrn_saver();
2992 if (!(flags & SCGETC_CN))
2993 /* do the /dev/random device a favour */
2994 add_keyboard_randomness(c);
2997 if (scp->kbd_mode != K_XLATE)
3000 /* if scroll-lock pressed allow history browsing */
3001 if (!ISGRAPHSC(scp) && scp->history && scp->status & SLKED) {
3003 scp->status &= ~CURSOR_ENABLED;
3004 sc_remove_cursor_image(scp);
3006 #ifndef SC_NO_HISTORY
3007 if (!(scp->status & BUFFER_SAVED)) {
3008 scp->status |= BUFFER_SAVED;
3012 /* FIXME: key codes */
3013 case SPCLKEY | FKEY | F(49): /* home key */
3014 sc_remove_cutmarking(scp);
3018 case SPCLKEY | FKEY | F(57): /* end key */
3019 sc_remove_cutmarking(scp);
3023 case SPCLKEY | FKEY | F(50): /* up arrow key */
3024 sc_remove_cutmarking(scp);
3025 if (sc_hist_up_line(scp))
3026 if (!(flags & SCGETC_CN))
3027 sc_bell(scp, bios_value.bell_pitch, BELL_DURATION);
3030 case SPCLKEY | FKEY | F(58): /* down arrow key */
3031 sc_remove_cutmarking(scp);
3032 if (sc_hist_down_line(scp))
3033 if (!(flags & SCGETC_CN))
3034 sc_bell(scp, bios_value.bell_pitch, BELL_DURATION);
3037 case SPCLKEY | FKEY | F(51): /* page up key */
3038 sc_remove_cutmarking(scp);
3039 for (i=0; i<scp->ysize; i++)
3040 if (sc_hist_up_line(scp)) {
3041 if (!(flags & SCGETC_CN))
3042 sc_bell(scp, bios_value.bell_pitch, BELL_DURATION);
3047 case SPCLKEY | FKEY | F(59): /* page down key */
3048 sc_remove_cutmarking(scp);
3049 for (i=0; i<scp->ysize; i++)
3050 if (sc_hist_down_line(scp)) {
3051 if (!(flags & SCGETC_CN))
3052 sc_bell(scp, bios_value.bell_pitch, BELL_DURATION);
3057 #endif /* SC_NO_HISTORY */
3061 * Process and consume special keys here. Return a plain char code
3062 * or a char code with the META flag or a function key code.
3066 /* goto next_code */
3071 switch (KEYCHAR(c)) {
3073 case NLK: case CLK: case ALK:
3076 kbd_ioctl(sc->kbd, KDGKBSTATE, (caddr_t)&f);
3078 scp->status |= SLKED;
3080 if (scp->status & SLKED) {
3081 scp->status &= ~SLKED;
3082 #ifndef SC_NO_HISTORY
3083 if (scp->status & BUFFER_SAVED) {
3084 if (!sc_hist_restore(scp))
3085 sc_remove_cutmarking(scp);
3086 scp->status &= ~BUFFER_SAVED;
3087 scp->status |= CURSOR_ENABLED;
3088 sc_draw_cursor_image(scp);
3090 tp = VIRTUAL_TTY(sc, scp->index);
3098 /* NON-LOCKING KEYS */
3100 case LSH: case RSH: case LCTR: case RCTR:
3101 case LALT: case RALT: case ASH: case META:
3105 if (!(sc->flags & SC_SCRN_BLANKED))
3111 /* force activatation/deactivation of the screen saver */
3112 if (!(sc->flags & SC_SCRN_BLANKED)) {
3113 run_scrn_saver = TRUE;
3114 sc->scrn_time_stamp -= scrn_blank_time;
3118 * While devices are being probed, the screen saver need
3119 * to be invoked explictly. XXX
3121 if (sc->flags & SC_SCRN_BLANKED) {
3122 scsplash_stick(FALSE);
3123 stop_scrn_saver(sc, current_saver);
3125 if (!ISGRAPHSC(scp)) {
3126 scsplash_stick(TRUE);
3127 (*current_saver)(sc, TRUE);
3131 #endif /* NSPLASH */
3135 #ifndef SC_DISABLE_REBOOT
3141 #ifndef SC_DISABLE_REBOOT
3142 shutdown_nice(RB_HALT);
3147 #ifndef SC_DISABLE_REBOOT
3148 shutdown_nice(RB_HALT|RB_POWEROFF);
3154 apm_suspend(PMST_SUSPEND);
3157 apm_suspend(PMST_STANDBY);
3166 #ifndef SC_DISABLE_DDBKEY
3168 Debugger("manual escape to debugger");
3170 printf("No debugger in kernel\n");
3172 #else /* SC_DISABLE_DDBKEY */
3174 #endif /* SC_DISABLE_DDBKEY */
3178 if (enable_panic_key)
3179 panic("Forced by the panic key");
3183 this_scr = scp->index;
3184 for (i = (this_scr - sc->first_vty + 1)%sc->vtys;
3185 sc->first_vty + i != this_scr;
3186 i = (i + 1)%sc->vtys) {
3187 struct tty *tp = VIRTUAL_TTY(sc, sc->first_vty + i);
3188 if (ISTTYOPEN(tp)) {
3189 sc_switch_scr(scp->sc, sc->first_vty + i);
3196 this_scr = scp->index;
3197 for (i = (this_scr - sc->first_vty + sc->vtys - 1)%sc->vtys;
3198 sc->first_vty + i != this_scr;
3199 i = (i + sc->vtys - 1)%sc->vtys) {
3200 struct tty *tp = VIRTUAL_TTY(sc, sc->first_vty + i);
3201 if (ISTTYOPEN(tp)) {
3202 sc_switch_scr(scp->sc, sc->first_vty + i);
3209 if (KEYCHAR(c) >= F_SCR && KEYCHAR(c) <= L_SCR) {
3210 sc_switch_scr(scp->sc, sc->first_vty + KEYCHAR(c) - F_SCR);
3213 /* assert(c & FKEY) */
3214 if (!(sc->flags & SC_SCRN_BLANKED))
3218 /* goto next_code */
3220 /* regular keys (maybe MKEY is set) */
3221 if (!(sc->flags & SC_SCRN_BLANKED))
3230 scmmap(dev_t dev, vm_offset_t offset, int nprot)
3235 if (scp != scp->sc->cur_scp)
3237 return (*vidsw[scp->sc->adapter]->mmap)(scp->sc->adp, offset, nprot);
3241 save_kbd_state(scr_stat *scp)
3246 error = kbd_ioctl(scp->sc->kbd, KDGKBSTATE, (caddr_t)&state);
3247 if (error == ENOIOCTL)
3250 scp->status &= ~LOCK_MASK;
3251 scp->status |= state;
3257 update_kbd_state(scr_stat *scp, int new_bits, int mask)
3262 if (mask != LOCK_MASK) {
3263 error = kbd_ioctl(scp->sc->kbd, KDGKBSTATE, (caddr_t)&state);
3264 if (error == ENOIOCTL)
3269 state |= new_bits & mask;
3271 state = new_bits & LOCK_MASK;
3273 error = kbd_ioctl(scp->sc->kbd, KDSKBSTATE, (caddr_t)&state);
3274 if (error == ENOIOCTL)
3280 update_kbd_leds(scr_stat *scp, int which)
3285 error = kbd_ioctl(scp->sc->kbd, KDSETLED, (caddr_t)&which);
3286 if (error == ENOIOCTL)
3292 set_mode(scr_stat *scp)
3296 /* reject unsupported mode */
3297 if ((*vidsw[scp->sc->adapter]->get_info)(scp->sc->adp, scp->mode, &info))
3300 /* if this vty is not currently showing, do nothing */
3301 if (scp != scp->sc->cur_scp)
3304 /* setup video hardware for the given mode */
3305 (*vidsw[scp->sc->adapter]->set_mode)(scp->sc->adp, scp->mode);
3306 sc_vtb_init(&scp->scr, VTB_FRAMEBUFFER, scp->xsize, scp->ysize,
3307 (void *)scp->sc->adp->va_window, FALSE);
3309 #ifndef SC_NO_FONT_LOADING
3310 /* load appropriate font */
3311 if (!(scp->status & GRAPHICS_MODE)) {
3312 if (!(scp->status & PIXEL_MODE) && ISFONTAVAIL(scp->sc->adp->va_flags)) {
3313 if (scp->font_size < 14) {
3314 if (scp->sc->fonts_loaded & FONT_8)
3315 sc_load_font(scp, 0, 8, scp->sc->font_8, 0, 256);
3316 } else if (scp->font_size >= 16) {
3317 if (scp->sc->fonts_loaded & FONT_16)
3318 sc_load_font(scp, 0, 16, scp->sc->font_16, 0, 256);
3320 if (scp->sc->fonts_loaded & FONT_14)
3321 sc_load_font(scp, 0, 14, scp->sc->font_14, 0, 256);
3325 * This is an interim kludge to display correct font.
3326 * Always use the font page #0 on the video plane 2.
3327 * Somehow we cannot show the font in other font pages on
3328 * some video cards... XXX
3330 sc_show_font(scp, 0);
3334 #endif /* !SC_NO_FONT_LOADING */
3336 sc_set_border(scp, scp->border);
3337 sc_set_cursor_image(scp);
3343 sc_set_border(scr_stat *scp, int color)
3345 ++scp->sc->videoio_in_progress;
3346 (*scp->rndr->draw_border)(scp, color);
3347 --scp->sc->videoio_in_progress;
3350 #ifndef SC_NO_FONT_LOADING
3352 sc_load_font(scr_stat *scp, int page, int size, u_char *buf,
3353 int base, int count)
3358 sc->font_loading_in_progress = TRUE;
3359 (*vidsw[sc->adapter]->load_font)(sc->adp, page, size, buf, base, count);
3360 sc->font_loading_in_progress = FALSE;
3364 sc_save_font(scr_stat *scp, int page, int size, u_char *buf,
3365 int base, int count)
3370 sc->font_loading_in_progress = TRUE;
3371 (*vidsw[sc->adapter]->save_font)(sc->adp, page, size, buf, base, count);
3372 sc->font_loading_in_progress = FALSE;
3376 sc_show_font(scr_stat *scp, int page)
3378 (*vidsw[scp->sc->adapter]->show_font)(scp->sc->adp, page);
3380 #endif /* !SC_NO_FONT_LOADING */
3383 sc_paste(scr_stat *scp, u_char *p, int count)
3388 if (scp->status & MOUSE_VISIBLE) {
3389 tp = VIRTUAL_TTY(scp->sc, scp->sc->cur_scp->index);
3392 rmap = scp->sc->scr_rmap;
3393 for (; count > 0; --count)
3394 (*linesw[tp->t_line].l_rint)(rmap[*p++], tp);
3399 sc_bell(scr_stat *scp, int pitch, int duration)
3401 if (cold || shutdown_in_progress)
3404 if (scp != scp->sc->cur_scp && (scp->sc->flags & SC_QUIET_BELL))
3407 if (scp->sc->flags & SC_VISUAL_BELL) {
3408 if (scp->sc->blink_in_progress)
3410 scp->sc->blink_in_progress = 3;
3411 if (scp != scp->sc->cur_scp)
3412 scp->sc->blink_in_progress += 2;
3413 blink_screen(scp->sc->cur_scp);
3415 if (scp != scp->sc->cur_scp)
3417 sysbeep(pitch, duration);
3422 blink_screen(void *arg)
3424 scr_stat *scp = arg;
3427 if (ISGRAPHSC(scp) || (scp->sc->blink_in_progress <= 1)) {
3428 scp->sc->blink_in_progress = 0;
3430 tp = VIRTUAL_TTY(scp->sc, scp->index);
3433 if (scp->sc->delayed_next_scr)
3434 sc_switch_scr(scp->sc, scp->sc->delayed_next_scr - 1);
3437 (*scp->rndr->draw)(scp, 0, scp->xsize*scp->ysize,
3438 scp->sc->blink_in_progress & 1);
3439 scp->sc->blink_in_progress--;
3440 timeout(blink_screen, scp, hz / 10);