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.6 2003/07/21 05:50:36 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 = {
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);
381 for (vc = 0; vc < sc->vtys; vc++) {
382 dev = make_dev(&sc_cdevsw, vc + unit * MAXCONS,
383 UID_ROOT, GID_WHEEL, 0600, "ttyv%r", vc + unit * MAXCONS);
386 * The first vty already has struct tty and scr_stat initialized
387 * in scinit(). The other vtys will have these structs when
392 dev = make_dev(&sc_cdevsw, SC_CONSOLECTL,
393 UID_ROOT, GID_WHEEL, 0600, "consolectl");
394 dev->si_tty = sc_console_tty = ttymalloc(sc_console_tty);
395 SC_STAT(dev) = sc_console;
408 * As soon as malloc() becomes functional, we had better allocate
409 * various buffers for the kernel console.
412 if (sc_console_unit < 0) /* sc_console == NULL */
415 /* copy the temporary buffer to the final buffer */
416 sc_alloc_scr_buffer(sc_console, FALSE, FALSE);
418 #ifndef SC_NO_CUTPASTE
419 sc_alloc_cut_buffer(sc_console, FALSE);
422 #ifndef SC_NO_HISTORY
423 /* initialize history buffer & pointers */
424 sc_alloc_history_buffer(sc_console, 0, 0, FALSE);
429 SYSINIT(sc_mem, SI_SUB_KMEM, SI_ORDER_ANY, scmeminit, NULL);
432 scdevtounit(dev_t dev)
434 int vty = SC_VTY(dev);
436 if (vty == SC_CONSOLECTL)
437 return ((sc_console != NULL) ? sc_console->sc->unit : -1);
438 else if ((vty < 0) || (vty >= MAXCONS*sc_max_unit()))
445 scopen(dev_t dev, int flag, int mode, struct thread *td)
447 int unit = scdevtounit(dev);
454 DPRINTF(5, ("scopen: dev:%d,%d, unit:%d, vty:%d\n",
455 major(dev), minor(dev), unit, SC_VTY(dev)));
457 sc = sc_get_softc(unit, (sc_console_unit == unit) ? SC_KERNEL_CONSOLE : 0);
461 tp = dev->si_tty = ttymalloc(dev->si_tty);
462 tp->t_oproc = scstart;
463 tp->t_param = scparam;
464 tp->t_stop = nottystop;
466 if (!ISTTYOPEN(tp)) {
468 /* Use the current setting of the <-- key as default VERASE. */
469 /* If the Delete key is preferable, an stty is necessary */
470 if (sc->kbd != NULL) {
471 key.keynum = KEYCODE_BS;
472 kbd_ioctl(sc->kbd, GIO_KEYMAPENT, (caddr_t)&key);
473 tp->t_cc[VERASE] = key.key.map[0];
475 tp->t_iflag = TTYDEF_IFLAG;
476 tp->t_oflag = TTYDEF_OFLAG;
477 tp->t_cflag = TTYDEF_CFLAG;
478 tp->t_lflag = TTYDEF_LFLAG;
479 tp->t_ispeed = tp->t_ospeed = TTYDEF_SPEED;
480 scparam(tp, &tp->t_termios);
481 (*linesw[tp->t_line].l_modem)(tp, 1);
484 if (tp->t_state & TS_XCLUDE && suser(td))
487 error = (*linesw[tp->t_line].l_open)(dev, tp);
491 scp = SC_STAT(dev) = alloc_scp(sc, SC_VTY(dev));
493 sc_set_pixel_mode(scp, NULL, COL, ROW, 16);
495 if (!tp->t_winsize.ws_col && !tp->t_winsize.ws_row) {
496 tp->t_winsize.ws_col = scp->xsize;
497 tp->t_winsize.ws_row = scp->ysize;
504 scclose(dev_t dev, int flag, int mode, struct thread *td)
506 struct tty *tp = dev->si_tty;
510 if (SC_VTY(dev) != SC_CONSOLECTL) {
511 scp = SC_STAT(tp->t_dev);
512 /* were we in the middle of the VT switching process? */
513 DPRINTF(5, ("sc%d: scclose(), ", scp->sc->unit));
515 if ((scp == scp->sc->cur_scp) && (scp->sc->unit == sc_console_unit))
516 cons_unavail = FALSE;
517 if (finish_vt_rel(scp, TRUE, &s) == 0) /* force release */
518 DPRINTF(5, ("reset WAIT_REL, "));
519 if (finish_vt_acq(scp) == 0) /* force acknowledge */
520 DPRINTF(5, ("reset WAIT_ACQ, "));
522 if (scp == &main_console) {
525 scp->smode.mode = VT_AUTO;
528 sc_vtb_destroy(&scp->vtb);
529 sc_vtb_destroy(&scp->scr);
530 sc_free_history_buffer(scp, scp->ysize);
537 scp->smode.mode = VT_AUTO;
539 scp->kbd_mode = K_XLATE;
540 if (scp == scp->sc->cur_scp)
541 kbd_ioctl(scp->sc->kbd, KDSKBMODE, (caddr_t)&scp->kbd_mode);
542 DPRINTF(5, ("done.\n"));
545 (*linesw[tp->t_line].l_close)(tp, flag);
552 scread(dev_t dev, struct uio *uio, int flag)
554 sc_touch_scrn_saver();
555 return ttyread(dev, uio, flag);
559 sckbdevent(keyboard_t *thiskbd, int event, void *arg)
567 sc = (sc_softc_t *)arg;
568 /* assert(thiskbd == sc->kbd) */
573 case KBDIO_UNLOADING:
576 kbd_release(thiskbd, (void *)&sc->keyboard);
583 * Loop while there is still input to get from the keyboard.
584 * I don't think this is nessesary, and it doesn't fix
585 * the Xaccel-2.1 keyboard hang, but it can't hurt. XXX
587 while ((c = scgetc(sc, SCGETC_NONBLOCK)) != NOKEY) {
589 cur_tty = VIRTUAL_TTY(sc, sc->cur_scp->index);
590 if (!ISTTYOPEN(cur_tty)) {
591 cur_tty = sc_console_tty;
592 if (!ISTTYOPEN(cur_tty))
596 if ((*sc->cur_scp->tsw->te_input)(sc->cur_scp, c, cur_tty))
599 switch (KEYFLAGS(c)) {
600 case 0x0000: /* normal key */
601 (*linesw[cur_tty->t_line].l_rint)(KEYCHAR(c), cur_tty);
603 case FKEY: /* function key, return string */
604 cp = kbd_get_fkeystr(thiskbd, KEYCHAR(c), &len);
607 (*linesw[cur_tty->t_line].l_rint)(*cp++, cur_tty);
610 case MKEY: /* meta is active, prepend ESC */
611 (*linesw[cur_tty->t_line].l_rint)(0x1b, cur_tty);
612 (*linesw[cur_tty->t_line].l_rint)(KEYCHAR(c), cur_tty);
614 case BKEY: /* backtab fixed sequence (esc [ Z) */
615 (*linesw[cur_tty->t_line].l_rint)(0x1b, cur_tty);
616 (*linesw[cur_tty->t_line].l_rint)('[', cur_tty);
617 (*linesw[cur_tty->t_line].l_rint)('Z', cur_tty);
622 sc->cur_scp->status |= MOUSE_HIDDEN;
628 scparam(struct tty *tp, struct termios *t)
630 tp->t_ispeed = t->c_ispeed;
631 tp->t_ospeed = t->c_ospeed;
632 tp->t_cflag = t->c_cflag;
637 scioctl(dev_t dev, u_long cmd, caddr_t data, int flag, struct thread *td)
645 struct proc *p = td->td_proc;
651 /* If there is a user_ioctl function call that first */
653 error = (*sc_user_ioctl)(dev, cmd, data, flag, td);
654 if (error != ENOIOCTL)
658 error = sc_vid_ioctl(tp, cmd, data, flag, td);
659 if (error != ENOIOCTL)
662 #ifndef SC_NO_HISTORY
663 error = sc_hist_ioctl(tp, cmd, data, flag, td);
664 if (error != ENOIOCTL)
668 #ifndef SC_NO_SYSMOUSE
669 error = sc_mouse_ioctl(tp, cmd, data, flag, td);
670 if (error != ENOIOCTL)
674 scp = SC_STAT(tp->t_dev);
675 /* assert(scp != NULL) */
676 /* scp is sc_console, if SC_VTY(dev) == SC_CONSOLECTL. */
680 error = (*scp->tsw->te_ioctl)(scp, tp, cmd, data, flag, td);
681 if (error != ENOIOCTL)
685 switch (cmd) { /* process console hardware related ioctl's */
687 case GIO_ATTR: /* get current attributes */
688 /* this ioctl is not processed here, but in the terminal emulator */
691 case GIO_COLOR: /* is this a color console ? */
692 *(int *)data = (sc->adp->va_flags & V_ADP_COLOR) ? 1 : 0;
695 case CONS_BLANKTIME: /* set screen saver timeout (0 = no saver) */
696 if (*(int *)data < 0 || *(int *)data > MAX_BLANKTIME)
699 scrn_blank_time = *(int *)data;
700 run_scrn_saver = (scrn_blank_time != 0);
704 case CONS_CURSORTYPE: /* set cursor type blink/noblink */
706 if (!ISGRAPHSC(sc->cur_scp))
707 sc_remove_cursor_image(sc->cur_scp);
708 if ((*(int*)data) & 0x01)
709 sc->flags |= SC_BLINK_CURSOR;
711 sc->flags &= ~SC_BLINK_CURSOR;
712 if ((*(int*)data) & 0x02) {
713 sc->flags |= SC_CHAR_CURSOR;
715 sc->flags &= ~SC_CHAR_CURSOR;
717 * The cursor shape is global property; all virtual consoles
718 * are affected. Update the cursor in the current console...
720 if (!ISGRAPHSC(sc->cur_scp)) {
721 sc_set_cursor_image(sc->cur_scp);
722 sc_draw_cursor_image(sc->cur_scp);
727 case CONS_BELLTYPE: /* set bell type sound/visual */
728 if ((*(int *)data) & 0x01)
729 sc->flags |= SC_VISUAL_BELL;
731 sc->flags &= ~SC_VISUAL_BELL;
732 if ((*(int *)data) & 0x02)
733 sc->flags |= SC_QUIET_BELL;
735 sc->flags &= ~SC_QUIET_BELL;
738 case CONS_GETINFO: /* get current (virtual) console info */
740 vid_info_t *ptr = (vid_info_t*)data;
741 if (ptr->size == sizeof(struct vid_info)) {
742 ptr->m_num = sc->cur_scp->index;
743 ptr->font_size = scp->font_size;
744 ptr->mv_col = scp->xpos;
745 ptr->mv_row = scp->ypos;
746 ptr->mv_csz = scp->xsize;
747 ptr->mv_rsz = scp->ysize;
749 * The following fields are filled by the terminal emulator. XXX
756 ptr->mv_grfc.fore = 0; /* not supported */
757 ptr->mv_grfc.back = 0; /* not supported */
758 ptr->mv_ovscan = scp->border;
759 if (scp == sc->cur_scp)
761 ptr->mk_keylock = scp->status & LOCK_MASK;
767 case CONS_GETVERS: /* get version number */
768 *(int*)data = 0x200; /* version 2.0 */
771 case CONS_IDLE: /* see if the screen has been idle */
773 * When the screen is in the GRAPHICS_MODE or UNKNOWN_MODE,
774 * the user process may have been writing something on the
775 * screen and syscons is not aware of it. Declare the screen
776 * is NOT idle if it is in one of these modes. But there is
777 * an exception to it; if a screen saver is running in the
778 * graphics mode in the current screen, we should say that the
779 * screen has been idle.
781 *(int *)data = (sc->flags & SC_SCRN_IDLE)
782 && (!ISGRAPHSC(sc->cur_scp)
783 || (sc->cur_scp->status & SAVER_RUNNING));
786 case CONS_SAVERMODE: /* set saver mode */
787 switch(*(int *)data) {
790 /* if a LKM screen saver is running, stop it first. */
791 scsplash_stick(FALSE);
792 saver_mode = *(int *)data;
795 if ((error = wait_scrn_saver_stop(NULL))) {
800 run_scrn_saver = TRUE;
801 if (saver_mode == CONS_USR_SAVER)
802 scp->status |= SAVER_RUNNING;
804 scp->status &= ~SAVER_RUNNING;
805 scsplash_stick(TRUE);
810 if ((saver_mode == CONS_USR_SAVER) && (scp->status & SAVER_RUNNING))
811 scp->status &= ~SAVER_RUNNING;
812 saver_mode = *(int *)data;
820 case CONS_SAVERSTART: /* immediately start/stop the screen saver */
822 * Note that this ioctl does not guarantee the screen saver
823 * actually starts or stops. It merely attempts to do so...
826 run_scrn_saver = (*(int *)data != 0);
828 sc->scrn_time_stamp -= scrn_blank_time;
832 case CONS_SCRSHOT: /* get a screen shot */
834 scrshot_t *ptr = (scrshot_t*)data;
836 if (ISGRAPHSC(scp)) {
840 if (scp->xsize != ptr->xsize || scp->ysize != ptr->ysize) {
844 copyout ((void*)scp->vtb.vtb_buffer, ptr->buf,
845 ptr->xsize * ptr->ysize * sizeof(u_int16_t));
850 case VT_SETMODE: /* set screen switcher mode */
852 struct vt_mode *mode;
854 mode = (struct vt_mode *)data;
855 DPRINTF(5, ("sc%d: VT_SETMODE ", sc->unit));
856 if (scp->smode.mode == VT_PROCESS) {
857 if (scp->proc == pfind(scp->pid) && scp->proc != p) {
858 DPRINTF(5, ("error EPERM\n"));
863 if (mode->mode == VT_AUTO) {
864 scp->smode.mode = VT_AUTO;
867 DPRINTF(5, ("VT_AUTO, "));
868 if ((scp == sc->cur_scp) && (sc->unit == sc_console_unit))
869 cons_unavail = FALSE;
870 /* were we in the middle of the vty switching process? */
871 if (finish_vt_rel(scp, TRUE, &s) == 0)
872 DPRINTF(5, ("reset WAIT_REL, "));
873 if (finish_vt_acq(scp) == 0)
874 DPRINTF(5, ("reset WAIT_ACQ, "));
876 if (!ISSIGVALID(mode->relsig) || !ISSIGVALID(mode->acqsig)
877 || !ISSIGVALID(mode->frsig)) {
879 DPRINTF(5, ("error EINVAL\n"));
882 DPRINTF(5, ("VT_PROCESS %d, ", p->p_pid));
883 bcopy(data, &scp->smode, sizeof(struct vt_mode));
885 scp->pid = scp->proc->p_pid;
886 if ((scp == sc->cur_scp) && (sc->unit == sc_console_unit))
894 case VT_GETMODE: /* get screen switcher mode */
895 bcopy(&scp->smode, data, sizeof(struct vt_mode));
898 case VT_RELDISP: /* screen switcher ioctl */
901 * This must be the current vty which is in the VT_PROCESS
904 if ((scp != sc->cur_scp) || (scp->smode.mode != VT_PROCESS)) {
908 /* ...and this process is controlling it. */
909 if (scp->proc != p) {
914 switch(*(int *)data) {
915 case VT_FALSE: /* user refuses to release screen, abort */
916 if ((error = finish_vt_rel(scp, FALSE, &s)) == 0)
917 DPRINTF(5, ("sc%d: VT_FALSE\n", sc->unit));
919 case VT_TRUE: /* user has released screen, go on */
920 if ((error = finish_vt_rel(scp, TRUE, &s)) == 0)
921 DPRINTF(5, ("sc%d: VT_TRUE\n", sc->unit));
923 case VT_ACKACQ: /* acquire acknowledged, switch completed */
924 if ((error = finish_vt_acq(scp)) == 0)
925 DPRINTF(5, ("sc%d: VT_ACKACQ\n", sc->unit));
933 case VT_OPENQRY: /* return free virtual console */
934 for (i = sc->first_vty; i < sc->first_vty + sc->vtys; i++) {
935 tp = VIRTUAL_TTY(sc, i);
936 if (!ISTTYOPEN(tp)) {
937 *(int *)data = i + 1;
943 case VT_ACTIVATE: /* switch to screen *data */
944 i = (*(int *)data == 0) ? scp->index : (*(int *)data - 1);
946 sc_clean_up(sc->cur_scp);
948 return sc_switch_scr(sc, i);
950 case VT_WAITACTIVE: /* wait for switch to occur */
951 i = (*(int *)data == 0) ? scp->index : (*(int *)data - 1);
952 if ((i < sc->first_vty) || (i >= sc->first_vty + sc->vtys))
955 error = sc_clean_up(sc->cur_scp);
959 scp = SC_STAT(SC_DEV(sc, i));
960 if (scp == scp->sc->cur_scp)
962 while ((error=tsleep((caddr_t)&scp->smode, PCATCH,
963 "waitvt", 0)) == ERESTART) ;
966 case VT_GETACTIVE: /* get active vty # */
967 *(int *)data = sc->cur_scp->index + 1;
970 case VT_GETINDEX: /* get this vty # */
971 *(int *)data = scp->index + 1;
974 case VT_LOCKSWITCH: /* prevent vty switching */
975 if ((*(int *)data) & 0x01)
976 sc->flags |= SC_SCRN_VTYLOCK;
978 sc->flags &= ~SC_SCRN_VTYLOCK;
981 case KDENABIO: /* allow io operations */
988 p->p_md.md_regs->tf_eflags |= PSL_IOPL;
992 case KDDISABIO: /* disallow io operations (default) */
994 p->p_md.md_regs->tf_eflags &= ~PSL_IOPL;
998 case KDSKBSTATE: /* set keyboard state (locks) */
999 if (*(int *)data & ~LOCK_MASK)
1001 scp->status &= ~LOCK_MASK;
1002 scp->status |= *(int *)data;
1003 if (scp == sc->cur_scp)
1004 update_kbd_state(scp, scp->status, LOCK_MASK);
1007 case KDGKBSTATE: /* get keyboard state (locks) */
1008 if (scp == sc->cur_scp)
1009 save_kbd_state(scp);
1010 *(int *)data = scp->status & LOCK_MASK;
1013 case KDGETREPEAT: /* get keyboard repeat & delay rates */
1014 case KDSETREPEAT: /* set keyboard repeat & delay rates (new) */
1015 error = kbd_ioctl(sc->kbd, cmd, data);
1016 if (error == ENOIOCTL)
1020 case KDSETRAD: /* set keyboard repeat & delay rates (old) */
1021 if (*(int *)data & ~0x7f)
1023 error = kbd_ioctl(sc->kbd, cmd, data);
1024 if (error == ENOIOCTL)
1028 case KDSKBMODE: /* set keyboard mode */
1029 switch (*(int *)data) {
1030 case K_XLATE: /* switch to XLT ascii mode */
1031 case K_RAW: /* switch to RAW scancode mode */
1032 case K_CODE: /* switch to CODE mode */
1033 scp->kbd_mode = *(int *)data;
1034 if (scp == sc->cur_scp)
1035 kbd_ioctl(sc->kbd, cmd, data);
1042 case KDGKBMODE: /* get keyboard mode */
1043 *(int *)data = scp->kbd_mode;
1047 error = kbd_ioctl(sc->kbd, cmd, data);
1048 if (error == ENOIOCTL)
1052 case KDMKTONE: /* sound the bell */
1054 sc_bell(scp, (*(int*)data)&0xffff,
1055 (((*(int*)data)>>16)&0xffff)*hz/1000);
1057 sc_bell(scp, scp->bell_pitch, scp->bell_duration);
1060 case KIOCSOUND: /* make tone (*data) hz */
1061 if (scp == sc->cur_scp) {
1063 return sc_tone(*(int *)data);
1069 case KDGKBTYPE: /* get keyboard type */
1070 error = kbd_ioctl(sc->kbd, cmd, data);
1071 if (error == ENOIOCTL) {
1072 /* always return something? XXX */
1077 case KDSETLED: /* set keyboard LED status */
1078 if (*(int *)data & ~LED_MASK) /* FIXME: LOCK_MASK? */
1080 scp->status &= ~LED_MASK;
1081 scp->status |= *(int *)data;
1082 if (scp == sc->cur_scp)
1083 update_kbd_leds(scp, scp->status);
1086 case KDGETLED: /* get keyboard LED status */
1087 if (scp == sc->cur_scp)
1088 save_kbd_state(scp);
1089 *(int *)data = scp->status & LED_MASK;
1092 case CONS_SETKBD: /* set the new keyboard */
1097 newkbd = kbd_get_keyboard(*(int *)data);
1098 if (newkbd == NULL) {
1103 if (sc->kbd != newkbd) {
1104 i = kbd_allocate(newkbd->kb_name, newkbd->kb_unit,
1105 (void *)&sc->keyboard, sckbdevent, sc);
1106 /* i == newkbd->kb_index */
1108 if (sc->kbd != NULL) {
1109 save_kbd_state(sc->cur_scp);
1110 kbd_release(sc->kbd, (void *)&sc->keyboard);
1112 sc->kbd = kbd_get_keyboard(i); /* sc->kbd == newkbd */
1114 kbd_ioctl(sc->kbd, KDSKBMODE,
1115 (caddr_t)&sc->cur_scp->kbd_mode);
1116 update_kbd_state(sc->cur_scp, sc->cur_scp->status,
1119 error = EPERM; /* XXX */
1126 case CONS_RELKBD: /* release the current keyboard */
1129 if (sc->kbd != NULL) {
1130 save_kbd_state(sc->cur_scp);
1131 error = kbd_release(sc->kbd, (void *)&sc->keyboard);
1140 case CONS_GETTERM: /* get the current terminal emulator info */
1144 if (((term_info_t *)data)->ti_index == 0) {
1147 sw = sc_term_match_by_number(((term_info_t *)data)->ti_index);
1150 strncpy(((term_info_t *)data)->ti_name, sw->te_name,
1151 sizeof(((term_info_t *)data)->ti_name));
1152 strncpy(((term_info_t *)data)->ti_desc, sw->te_desc,
1153 sizeof(((term_info_t *)data)->ti_desc));
1154 ((term_info_t *)data)->ti_flags = 0;
1157 ((term_info_t *)data)->ti_name[0] = '\0';
1158 ((term_info_t *)data)->ti_desc[0] = '\0';
1159 ((term_info_t *)data)->ti_flags = 0;
1164 case CONS_SETTERM: /* set the current terminal emulator */
1166 error = sc_init_emulator(scp, ((term_info_t *)data)->ti_name);
1167 /* FIXME: what if scp == sc_console! XXX */
1171 case GIO_SCRNMAP: /* get output translation table */
1172 bcopy(&sc->scr_map, data, sizeof(sc->scr_map));
1175 case PIO_SCRNMAP: /* set output translation table */
1176 bcopy(data, &sc->scr_map, sizeof(sc->scr_map));
1177 for (i=0; i<sizeof(sc->scr_map); i++) {
1178 sc->scr_rmap[sc->scr_map[i]] = i;
1182 case GIO_KEYMAP: /* get keyboard translation table */
1183 case PIO_KEYMAP: /* set keyboard translation table */
1184 case GIO_DEADKEYMAP: /* get accent key translation table */
1185 case PIO_DEADKEYMAP: /* set accent key translation table */
1186 case GETFKEY: /* get function key string */
1187 case SETFKEY: /* set function key string */
1188 error = kbd_ioctl(sc->kbd, cmd, data);
1189 if (error == ENOIOCTL)
1193 #ifndef SC_NO_FONT_LOADING
1195 case PIO_FONT8x8: /* set 8x8 dot font */
1196 if (!ISFONTAVAIL(sc->adp->va_flags))
1198 bcopy(data, sc->font_8, 8*256);
1199 sc->fonts_loaded |= FONT_8;
1202 * Always use the font page #0. XXX
1203 * Don't load if the current font size is not 8x8.
1205 if (ISTEXTSC(sc->cur_scp) && (sc->cur_scp->font_size < 14))
1206 sc_load_font(sc->cur_scp, 0, 8, sc->font_8, 0, 256);
1209 case GIO_FONT8x8: /* get 8x8 dot font */
1210 if (!ISFONTAVAIL(sc->adp->va_flags))
1212 if (sc->fonts_loaded & FONT_8) {
1213 bcopy(sc->font_8, data, 8*256);
1219 case PIO_FONT8x14: /* set 8x14 dot font */
1220 if (!ISFONTAVAIL(sc->adp->va_flags))
1222 bcopy(data, sc->font_14, 14*256);
1223 sc->fonts_loaded |= FONT_14;
1226 * Always use the font page #0. XXX
1227 * Don't load if the current font size is not 8x14.
1229 if (ISTEXTSC(sc->cur_scp)
1230 && (sc->cur_scp->font_size >= 14)
1231 && (sc->cur_scp->font_size < 16))
1232 sc_load_font(sc->cur_scp, 0, 14, sc->font_14, 0, 256);
1235 case GIO_FONT8x14: /* get 8x14 dot font */
1236 if (!ISFONTAVAIL(sc->adp->va_flags))
1238 if (sc->fonts_loaded & FONT_14) {
1239 bcopy(sc->font_14, data, 14*256);
1245 case PIO_FONT8x16: /* set 8x16 dot font */
1246 if (!ISFONTAVAIL(sc->adp->va_flags))
1248 bcopy(data, sc->font_16, 16*256);
1249 sc->fonts_loaded |= FONT_16;
1252 * Always use the font page #0. XXX
1253 * Don't load if the current font size is not 8x16.
1255 if (ISTEXTSC(sc->cur_scp) && (sc->cur_scp->font_size >= 16))
1256 sc_load_font(sc->cur_scp, 0, 16, sc->font_16, 0, 256);
1259 case GIO_FONT8x16: /* get 8x16 dot font */
1260 if (!ISFONTAVAIL(sc->adp->va_flags))
1262 if (sc->fonts_loaded & FONT_16) {
1263 bcopy(sc->font_16, data, 16*256);
1269 #endif /* SC_NO_FONT_LOADING */
1275 error = (*linesw[tp->t_line].l_ioctl)(tp, cmd, data, flag, td);
1276 if (error != ENOIOCTL)
1278 error = ttioctl(tp, cmd, data, flag);
1279 if (error != ENOIOCTL)
1285 scstart(struct tty *tp)
1289 u_char buf[PCBURST];
1290 scr_stat *scp = SC_STAT(tp->t_dev);
1292 if (scp->status & SLKED || scp->sc->blink_in_progress)
1295 if (!(tp->t_state & (TS_TIMEOUT | TS_BUSY | TS_TTSTOP))) {
1296 tp->t_state |= TS_BUSY;
1299 len = q_to_b(rbp, buf, PCBURST);
1301 sc_puts(scp, buf, len);
1304 tp->t_state &= ~TS_BUSY;
1311 sccnprobe(struct consdev *cp)
1317 cp->cn_pri = sc_get_cons_priority(&unit, &flags);
1319 /* a video card is always required */
1320 if (!scvidprobe(unit, flags, TRUE))
1321 cp->cn_pri = CN_DEAD;
1323 /* syscons will become console even when there is no keyboard */
1324 sckbdprobe(unit, flags, TRUE);
1326 if (cp->cn_pri == CN_DEAD)
1329 /* initialize required fields */
1330 cp->cn_dev = makedev(CDEV_MAJOR, SC_CONSOLECTL);
1331 #endif /* __i386__ */
1335 * alpha use sccnattach() rather than cnprobe()/cninit()/cnterm()
1336 * interface to install the console. Always return CN_DEAD from
1339 cp->cn_pri = CN_DEAD;
1340 #endif /* __alpha__ */
1344 sccninit(struct consdev *cp)
1350 sc_get_cons_priority(&unit, &flags);
1351 scinit(unit, flags | SC_KERNEL_CONSOLE);
1352 sc_console_unit = unit;
1353 sc_console = SC_STAT(sc_get_softc(unit, SC_KERNEL_CONSOLE)->dev[0]);
1354 #endif /* __i386__ */
1357 /* SHOULDN'T REACH HERE */
1358 #endif /* __alpha__ */
1362 sccnterm(struct consdev *cp)
1364 /* we are not the kernel console any more, release everything */
1366 if (sc_console_unit < 0)
1367 return; /* shouldn't happen */
1371 sc_clear_screen(sc_console);
1372 sccnupdate(sc_console);
1374 scterm(sc_console_unit, SC_KERNEL_CONSOLE);
1375 sc_console_unit = -1;
1377 #endif /* __i386__ */
1380 /* do nothing XXX */
1381 #endif /* __alpha__ */
1389 static struct consdev consdev;
1393 bcopy(&sc_consdev, &consdev, sizeof(sc_consdev));
1394 consdev.cn_pri = sc_get_cons_priority(&unit, &flags);
1396 /* a video card is always required */
1397 if (!scvidprobe(unit, flags, TRUE))
1398 consdev.cn_pri = CN_DEAD;
1400 /* alpha doesn't allow the console being without a keyboard... Why? */
1401 if (!sckbdprobe(unit, flags, TRUE))
1402 consdev.cn_pri = CN_DEAD;
1404 if (consdev.cn_pri == CN_DEAD)
1407 scinit(unit, flags | SC_KERNEL_CONSOLE);
1408 sc_console_unit = unit;
1409 sc_console = SC_STAT(sc_get_softc(unit, SC_KERNEL_CONSOLE)->dev[0]);
1410 consdev.cn_dev = makedev(CDEV_MAJOR, 0);
1414 #endif /* __alpha__ */
1417 sccnputc(dev_t dev, int c)
1420 scr_stat *scp = sc_console;
1422 #ifndef SC_NO_HISTORY
1424 #endif /* !SC_NO_HISTORY */
1427 /* assert(sc_console != NULL) */
1429 #ifndef SC_NO_HISTORY
1430 if (scp == scp->sc->cur_scp && scp->status & SLKED) {
1431 scp->status &= ~SLKED;
1432 update_kbd_state(scp, scp->status, SLKED);
1433 if (scp->status & BUFFER_SAVED) {
1434 if (!sc_hist_restore(scp))
1435 sc_remove_cutmarking(scp);
1436 scp->status &= ~BUFFER_SAVED;
1437 scp->status |= CURSOR_ENABLED;
1438 sc_draw_cursor_image(scp);
1440 tp = VIRTUAL_TTY(scp->sc, scp->index);
1444 #endif /* !SC_NO_HISTORY */
1447 if (kernel_console_ts != NULL)
1448 scp->ts = kernel_console_ts;
1450 sc_puts(scp, buf, 1);
1453 s = spltty(); /* block sckbdevent and scrn_timer */
1461 return sccngetch(0);
1465 sccncheckc(dev_t dev)
1467 return sccngetch(SCGETC_NONBLOCK);
1471 sccndbctl(dev_t dev, int on)
1473 /* assert(sc_console_unit >= 0) */
1474 /* try to switch to the kernel console screen */
1475 if (on && debugger == 0) {
1477 * TRY to make sure the screen saver is stopped,
1478 * and the screen is updated before switching to
1483 && sc_console->sc->cur_scp->smode.mode == VT_AUTO
1484 && sc_console->smode.mode == VT_AUTO) {
1485 sc_console->sc->cur_scp->status |= MOUSE_HIDDEN;
1486 sc_switch_scr(sc_console->sc, sc_console->index);
1496 sccngetch(int flags)
1498 static struct fkeytab fkey;
1503 int s = spltty(); /* block sckbdevent and scrn_timer while we poll */
1506 /* assert(sc_console != NULL) */
1509 * Stop the screen saver and update the screen if necessary.
1510 * What if we have been running in the screen saver code... XXX
1512 sc_touch_scrn_saver();
1513 scp = sc_console->sc->cur_scp; /* XXX */
1516 if (fkeycp < fkey.len) {
1518 return fkey.str[fkeycp++];
1521 if (scp->sc->kbd == NULL) {
1527 * Make sure the keyboard is accessible even when the kbd device
1528 * driver is disabled.
1530 kbd_enable(scp->sc->kbd);
1532 /* we shall always use the keyboard in the XLATE mode here */
1533 cur_mode = scp->kbd_mode;
1534 scp->kbd_mode = K_XLATE;
1535 kbd_ioctl(scp->sc->kbd, KDSKBMODE, (caddr_t)&scp->kbd_mode);
1537 kbd_poll(scp->sc->kbd, TRUE);
1538 c = scgetc(scp->sc, SCGETC_CN | flags);
1539 kbd_poll(scp->sc->kbd, FALSE);
1541 scp->kbd_mode = cur_mode;
1542 kbd_ioctl(scp->sc->kbd, KDSKBMODE, (caddr_t)&scp->kbd_mode);
1543 kbd_disable(scp->sc->kbd);
1546 switch (KEYFLAGS(c)) {
1547 case 0: /* normal char */
1549 case FKEY: /* function key */
1550 p = kbd_get_fkeystr(scp->sc->kbd, KEYCHAR(c), (size_t *)&fkeycp);
1552 if ((p != NULL) && (fkey.len > 0)) {
1553 bcopy(p, fkey.str, fkey.len);
1567 sccnupdate(scr_stat *scp)
1569 /* this is a cut-down version of scrn_timer()... */
1571 if (scp->sc->font_loading_in_progress || scp->sc->videoio_in_progress)
1574 if (debugger > 0 || panicstr || shutdown_in_progress) {
1575 sc_touch_scrn_saver();
1576 } else if (scp != scp->sc->cur_scp) {
1580 if (!run_scrn_saver)
1581 scp->sc->flags &= ~SC_SCRN_IDLE;
1583 if ((saver_mode != CONS_LKM_SAVER) || !(scp->sc->flags & SC_SCRN_IDLE))
1584 if (scp->sc->flags & SC_SCRN_BLANKED)
1585 stop_scrn_saver(scp->sc, current_saver);
1586 #endif /* NSPLASH */
1588 if (scp != scp->sc->cur_scp || scp->sc->blink_in_progress
1589 || scp->sc->switch_in_progress)
1592 * FIXME: unlike scrn_timer(), we call scrn_update() from here even
1593 * when write_in_progress is non-zero. XXX
1596 if (!ISGRAPHSC(scp) && !(scp->sc->flags & SC_SCRN_BLANKED))
1597 scrn_update(scp, TRUE);
1601 scrn_timer(void *arg)
1603 static int kbd_interval = 0;
1610 again = (arg != NULL);
1612 sc = (sc_softc_t *)arg;
1613 else if (sc_console != NULL)
1614 sc = sc_console->sc;
1618 /* don't do anything when we are performing some I/O operations */
1619 if (sc->font_loading_in_progress || sc->videoio_in_progress) {
1621 timeout(scrn_timer, sc, hz / 10);
1626 if ((sc->kbd == NULL) && (sc->config & SC_AUTODETECT_KBD)) {
1627 /* try to allocate a keyboard automatically */
1628 if (++kbd_interval >= 25) {
1629 sc->keyboard = kbd_allocate("*", -1, (void *)&sc->keyboard,
1631 if (sc->keyboard >= 0) {
1632 sc->kbd = kbd_get_keyboard(sc->keyboard);
1633 kbd_ioctl(sc->kbd, KDSKBMODE,
1634 (caddr_t)&sc->cur_scp->kbd_mode);
1635 update_kbd_state(sc->cur_scp, sc->cur_scp->status,
1642 /* find the vty to update */
1645 /* should we stop the screen saver? */
1646 getmicrouptime(&tv);
1647 if (debugger > 0 || panicstr || shutdown_in_progress)
1648 sc_touch_scrn_saver();
1649 if (run_scrn_saver) {
1650 if (tv.tv_sec > sc->scrn_time_stamp + scrn_blank_time)
1651 sc->flags |= SC_SCRN_IDLE;
1653 sc->flags &= ~SC_SCRN_IDLE;
1655 sc->scrn_time_stamp = tv.tv_sec;
1656 sc->flags &= ~SC_SCRN_IDLE;
1657 if (scrn_blank_time > 0)
1658 run_scrn_saver = TRUE;
1661 if ((saver_mode != CONS_LKM_SAVER) || !(sc->flags & SC_SCRN_IDLE))
1662 if (sc->flags & SC_SCRN_BLANKED)
1663 stop_scrn_saver(sc, current_saver);
1664 #endif /* NSPLASH */
1666 /* should we just return ? */
1667 if (sc->blink_in_progress || sc->switch_in_progress
1668 || sc->write_in_progress) {
1670 timeout(scrn_timer, sc, hz / 10);
1675 /* Update the screen */
1676 scp = sc->cur_scp; /* cur_scp may have changed... */
1677 if (!ISGRAPHSC(scp) && !(sc->flags & SC_SCRN_BLANKED))
1678 scrn_update(scp, TRUE);
1681 /* should we activate the screen saver? */
1682 if ((saver_mode == CONS_LKM_SAVER) && (sc->flags & SC_SCRN_IDLE))
1683 if (!ISGRAPHSC(scp) || (sc->flags & SC_SCRN_BLANKED))
1684 (*current_saver)(sc, TRUE);
1685 #endif /* NSPLASH */
1688 timeout(scrn_timer, sc, hz / 25);
1693 and_region(int *s1, int *e1, int s2, int e2)
1695 if (*e1 < s2 || e2 < *s1)
1697 *s1 = imax(*s1, s2);
1698 *e1 = imin(*e1, e2);
1703 scrn_update(scr_stat *scp, int show_cursor)
1710 /* assert(scp == scp->sc->cur_scp) */
1712 ++scp->sc->videoio_in_progress;
1714 #ifndef SC_NO_CUTPASTE
1715 /* remove the previous mouse pointer image if necessary */
1716 if (scp->status & MOUSE_VISIBLE) {
1718 e = scp->mouse_pos + scp->xsize + 1;
1719 if ((scp->status & (MOUSE_MOVED | MOUSE_HIDDEN))
1720 || and_region(&s, &e, scp->start, scp->end)
1721 || ((scp->status & CURSOR_ENABLED) &&
1722 (scp->cursor_pos != scp->cursor_oldpos) &&
1723 (and_region(&s, &e, scp->cursor_pos, scp->cursor_pos)
1724 || and_region(&s, &e, scp->cursor_oldpos, scp->cursor_oldpos)))) {
1725 sc_remove_mouse_image(scp);
1726 if (scp->end >= scp->xsize*scp->ysize)
1727 scp->end = scp->xsize*scp->ysize - 1;
1730 #endif /* !SC_NO_CUTPASTE */
1734 if (scp->end >= scp->xsize*scp->ysize) {
1735 printf("scrn_update(): scp->end %d > size_of_screen!!\n", scp->end);
1736 scp->end = scp->xsize*scp->ysize - 1;
1738 if (scp->start < 0) {
1739 printf("scrn_update(): scp->start %d < 0\n", scp->start);
1744 /* update screen image */
1745 if (scp->start <= scp->end) {
1746 if (scp->mouse_cut_end >= 0) {
1747 /* there is a marked region for cut & paste */
1748 if (scp->mouse_cut_start <= scp->mouse_cut_end) {
1749 start = scp->mouse_cut_start;
1750 end = scp->mouse_cut_end;
1752 start = scp->mouse_cut_end;
1753 end = scp->mouse_cut_start - 1;
1757 /* does the cut-mark region overlap with the update region? */
1758 if (and_region(&s, &e, scp->start, scp->end)) {
1759 (*scp->rndr->draw)(scp, s, e - s + 1, TRUE);
1762 if (and_region(&s, &e, scp->start, scp->end))
1763 (*scp->rndr->draw)(scp, s, e - s + 1, FALSE);
1765 e = scp->xsize*scp->ysize - 1;
1766 if (and_region(&s, &e, scp->start, scp->end))
1767 (*scp->rndr->draw)(scp, s, e - s + 1, FALSE);
1769 (*scp->rndr->draw)(scp, scp->start,
1770 scp->end - scp->start + 1, FALSE);
1773 (*scp->rndr->draw)(scp, scp->start,
1774 scp->end - scp->start + 1, FALSE);
1778 /* we are not to show the cursor and the mouse pointer... */
1781 scp->start = scp->xsize*scp->ysize - 1;
1782 --scp->sc->videoio_in_progress;
1786 /* update cursor image */
1787 if (scp->status & CURSOR_ENABLED) {
1790 /* did cursor move since last time ? */
1791 if (scp->cursor_pos != scp->cursor_oldpos) {
1792 /* do we need to remove old cursor image ? */
1793 if (!and_region(&s, &e, scp->cursor_oldpos, scp->cursor_oldpos))
1794 sc_remove_cursor_image(scp);
1795 sc_draw_cursor_image(scp);
1797 if (and_region(&s, &e, scp->cursor_pos, scp->cursor_pos))
1798 /* cursor didn't move, but has been overwritten */
1799 sc_draw_cursor_image(scp);
1800 else if (scp->sc->flags & SC_BLINK_CURSOR)
1801 /* if it's a blinking cursor, update it */
1802 (*scp->rndr->blink_cursor)(scp, scp->cursor_pos,
1803 sc_inside_cutmark(scp,
1808 #ifndef SC_NO_CUTPASTE
1809 /* update "pseudo" mouse pointer image */
1810 if (scp->sc->flags & SC_MOUSE_ENABLED) {
1811 if (!(scp->status & (MOUSE_VISIBLE | MOUSE_HIDDEN))) {
1812 scp->status &= ~MOUSE_MOVED;
1813 sc_draw_mouse_image(scp);
1816 #endif /* SC_NO_CUTPASTE */
1819 scp->start = scp->xsize*scp->ysize - 1;
1821 --scp->sc->videoio_in_progress;
1826 scsplash_callback(int event, void *arg)
1831 sc = (sc_softc_t *)arg;
1835 if (add_scrn_saver(scsplash_saver) == 0) {
1836 sc->flags &= ~SC_SAVER_FAILED;
1837 run_scrn_saver = TRUE;
1838 if (cold && !(boothowto & (RB_VERBOSE | RB_CONFIG))) {
1839 scsplash_stick(TRUE);
1840 (*current_saver)(sc, TRUE);
1846 if (current_saver == scsplash_saver) {
1847 scsplash_stick(FALSE);
1848 error = remove_scrn_saver(scsplash_saver);
1860 scsplash_saver(sc_softc_t *sc, int show)
1862 static int busy = FALSE;
1871 if (!(sc->flags & SC_SAVER_FAILED)) {
1872 if (!(sc->flags & SC_SCRN_BLANKED))
1873 set_scrn_saver_mode(scp, -1, NULL, 0);
1874 switch (splash(sc->adp, TRUE)) {
1875 case 0: /* succeeded */
1877 case EAGAIN: /* try later */
1878 restore_scrn_saver_mode(scp, FALSE);
1879 sc_touch_scrn_saver(); /* XXX */
1882 sc->flags |= SC_SAVER_FAILED;
1883 scsplash_stick(FALSE);
1884 restore_scrn_saver_mode(scp, TRUE);
1885 printf("scsplash_saver(): failed to put up the image\n");
1889 } else if (!sticky_splash) {
1890 if ((sc->flags & SC_SCRN_BLANKED) && (splash(sc->adp, FALSE) == 0))
1891 restore_scrn_saver_mode(scp, TRUE);
1897 add_scrn_saver(void (*this_saver)(sc_softc_t *, int))
1902 if (current_saver != none_saver) {
1903 error = remove_scrn_saver(current_saver);
1908 if (current_saver != none_saver)
1911 run_scrn_saver = FALSE;
1912 saver_mode = CONS_LKM_SAVER;
1913 current_saver = this_saver;
1918 remove_scrn_saver(void (*this_saver)(sc_softc_t *, int))
1920 if (current_saver != this_saver)
1925 * In order to prevent `current_saver' from being called by
1926 * the timeout routine `scrn_timer()' while we manipulate
1927 * the saver list, we shall set `current_saver' to `none_saver'
1928 * before stopping the current saver, rather than blocking by `splXX()'.
1930 current_saver = none_saver;
1932 stop_scrn_saver(this_saver);
1935 /* unblank all blanked screens */
1936 wait_scrn_saver_stop(NULL);
1940 current_saver = none_saver;
1945 set_scrn_saver_mode(scr_stat *scp, int mode, u_char *pal, int border)
1949 /* assert(scp == scp->sc->cur_scp) */
1951 if (!ISGRAPHSC(scp))
1952 sc_remove_cursor_image(scp);
1953 scp->splash_save_mode = scp->mode;
1954 scp->splash_save_status = scp->status & (GRAPHICS_MODE | PIXEL_MODE);
1955 scp->status &= ~(GRAPHICS_MODE | PIXEL_MODE);
1956 scp->status |= (UNKNOWN_MODE | SAVER_RUNNING);
1957 scp->sc->flags |= SC_SCRN_BLANKED;
1963 if (set_mode(scp) == 0) {
1964 if (scp->sc->adp->va_info.vi_flags & V_INFO_GRAPHICS)
1965 scp->status |= GRAPHICS_MODE;
1966 #ifndef SC_NO_PALETTE_LOADING
1968 load_palette(scp->sc->adp, pal);
1970 sc_set_border(scp, border);
1974 scp->mode = scp->splash_save_mode;
1975 scp->status &= ~(UNKNOWN_MODE | SAVER_RUNNING);
1976 scp->status |= scp->splash_save_status;
1983 restore_scrn_saver_mode(scr_stat *scp, int changemode)
1989 /* assert(scp == scp->sc->cur_scp) */
1992 status = scp->status;
1993 scp->mode = scp->splash_save_mode;
1994 scp->status &= ~(UNKNOWN_MODE | SAVER_RUNNING);
1995 scp->status |= scp->splash_save_status;
1996 scp->sc->flags &= ~SC_SCRN_BLANKED;
1998 if (!ISGRAPHSC(scp))
1999 sc_draw_cursor_image(scp);
2004 if (set_mode(scp) == 0) {
2005 #ifndef SC_NO_PALETTE_LOADING
2006 load_palette(scp->sc->adp, scp->sc->palette);
2013 scp->status = status;
2020 stop_scrn_saver(sc_softc_t *sc, void (*saver)(sc_softc_t *, int))
2022 (*saver)(sc, FALSE);
2023 run_scrn_saver = FALSE;
2024 /* the screen saver may have chosen not to stop after all... */
2025 if (sc->flags & SC_SCRN_BLANKED)
2028 mark_all(sc->cur_scp);
2029 if (sc->delayed_next_scr)
2030 sc_switch_scr(sc, sc->delayed_next_scr - 1);
2031 wakeup((caddr_t)&scrn_blanked);
2035 wait_scrn_saver_stop(sc_softc_t *sc)
2039 while (scrn_blanked > 0) {
2040 run_scrn_saver = FALSE;
2041 if (sc && !(sc->flags & SC_SCRN_BLANKED)) {
2045 error = tsleep((caddr_t)&scrn_blanked, PCATCH, "scrsav", 0);
2046 if ((error != 0) && (error != ERESTART))
2049 run_scrn_saver = FALSE;
2052 #endif /* NSPLASH */
2055 sc_touch_scrn_saver(void)
2057 scsplash_stick(FALSE);
2058 run_scrn_saver = FALSE;
2062 sc_switch_scr(sc_softc_t *sc, u_int next_scr)
2068 DPRINTF(5, ("sc0: sc_switch_scr() %d ", next_scr + 1));
2070 /* prevent switch if previously requested */
2071 if (sc->flags & SC_SCRN_VTYLOCK) {
2072 sc_bell(sc->cur_scp, sc->cur_scp->bell_pitch,
2073 sc->cur_scp->bell_duration);
2077 /* delay switch if the screen is blanked or being updated */
2078 if ((sc->flags & SC_SCRN_BLANKED) || sc->write_in_progress
2079 || sc->blink_in_progress || sc->videoio_in_progress) {
2080 sc->delayed_next_scr = next_scr + 1;
2081 sc_touch_scrn_saver();
2082 DPRINTF(5, ("switch delayed\n"));
2087 cur_scp = sc->cur_scp;
2089 /* we are in the middle of the vty switching process... */
2090 if (sc->switch_in_progress
2091 && (cur_scp->smode.mode == VT_PROCESS)
2093 if (cur_scp->proc != pfind(cur_scp->pid)) {
2095 * The controlling process has died!!. Do some clean up.
2096 * NOTE:`cur_scp->proc' and `cur_scp->smode.mode'
2097 * are not reset here yet; they will be cleared later.
2099 DPRINTF(5, ("cur_scp controlling process %d died, ",
2101 if (cur_scp->status & SWITCH_WAIT_REL) {
2103 * Force the previous switch to finish, but return now
2106 DPRINTF(5, ("reset WAIT_REL, "));
2107 finish_vt_rel(cur_scp, TRUE, &s);
2109 DPRINTF(5, ("finishing previous switch\n"));
2111 } else if (cur_scp->status & SWITCH_WAIT_ACQ) {
2112 /* let's assume screen switch has been completed. */
2113 DPRINTF(5, ("reset WAIT_ACQ, "));
2114 finish_vt_acq(cur_scp);
2117 * We are in between screen release and acquisition, and
2118 * reached here via scgetc() or scrn_timer() which has
2119 * interrupted exchange_scr(). Don't do anything stupid.
2121 DPRINTF(5, ("waiting nothing, "));
2125 * The controlling process is alive, but not responding...
2126 * It is either buggy or it may be just taking time.
2127 * The following code is a gross kludge to cope with this
2128 * problem for which there is no clean solution. XXX
2130 if (cur_scp->status & SWITCH_WAIT_REL) {
2131 switch (sc->switch_in_progress++) {
2135 DPRINTF(5, ("sending relsig again, "));
2136 signal_vt_rel(cur_scp);
2143 * Act as if the controlling program returned
2146 DPRINTF(5, ("force reset WAIT_REL, "));
2147 finish_vt_rel(cur_scp, FALSE, &s);
2149 DPRINTF(5, ("act as if VT_FALSE was seen\n"));
2152 } else if (cur_scp->status & SWITCH_WAIT_ACQ) {
2153 switch (sc->switch_in_progress++) {
2157 DPRINTF(5, ("sending acqsig again, "));
2158 signal_vt_acq(cur_scp);
2164 /* clear the flag and finish the previous switch */
2165 DPRINTF(5, ("force reset WAIT_ACQ, "));
2166 finish_vt_acq(cur_scp);
2174 * Return error if an invalid argument is given, or vty switch
2175 * is still in progress.
2177 if ((next_scr < sc->first_vty) || (next_scr >= sc->first_vty + sc->vtys)
2178 || sc->switch_in_progress) {
2180 sc_bell(cur_scp, bios_value.bell_pitch, BELL_DURATION);
2181 DPRINTF(5, ("error 1\n"));
2186 * Don't allow switching away from the graphics mode vty
2187 * if the switch mode is VT_AUTO, unless the next vty is the same
2188 * as the current or the current vty has been closed (but showing).
2190 tp = VIRTUAL_TTY(sc, cur_scp->index);
2191 if ((cur_scp->index != next_scr)
2193 && (cur_scp->smode.mode == VT_AUTO)
2194 && ISGRAPHSC(cur_scp)) {
2196 sc_bell(cur_scp, bios_value.bell_pitch, BELL_DURATION);
2197 DPRINTF(5, ("error, graphics mode\n"));
2202 * Is the wanted vty open? Don't allow switching to a closed vty.
2203 * If we are in DDB, don't switch to a vty in the VT_PROCESS mode.
2204 * Note that we always allow the user to switch to the kernel
2205 * console even if it is closed.
2207 if ((sc_console == NULL) || (next_scr != sc_console->index)) {
2208 tp = VIRTUAL_TTY(sc, next_scr);
2209 if (!ISTTYOPEN(tp)) {
2211 sc_bell(cur_scp, bios_value.bell_pitch, BELL_DURATION);
2212 DPRINTF(5, ("error 2, requested vty isn't open!\n"));
2215 if ((debugger > 0) && (SC_STAT(tp->t_dev)->smode.mode == VT_PROCESS)) {
2217 DPRINTF(5, ("error 3, requested vty is in the VT_PROCESS mode\n"));
2222 /* this is the start of vty switching process... */
2223 ++sc->switch_in_progress;
2224 sc->delayed_next_scr = 0;
2225 sc->old_scp = cur_scp;
2226 sc->new_scp = SC_STAT(SC_DEV(sc, next_scr));
2227 if (sc->new_scp == sc->old_scp) {
2228 sc->switch_in_progress = 0;
2229 wakeup((caddr_t)&sc->new_scp->smode);
2231 DPRINTF(5, ("switch done (new == old)\n"));
2235 /* has controlling process died? */
2236 vt_proc_alive(sc->old_scp);
2237 vt_proc_alive(sc->new_scp);
2239 /* wait for the controlling process to release the screen, if necessary */
2240 if (signal_vt_rel(sc->old_scp)) {
2245 /* go set up the new vty screen */
2250 /* wake up processes waiting for this vty */
2251 wakeup((caddr_t)&sc->cur_scp->smode);
2253 /* wait for the controlling process to acknowledge, if necessary */
2254 if (signal_vt_acq(sc->cur_scp)) {
2259 sc->switch_in_progress = 0;
2260 if (sc->unit == sc_console_unit)
2261 cons_unavail = FALSE;
2263 DPRINTF(5, ("switch done\n"));
2269 do_switch_scr(sc_softc_t *sc, int s)
2271 vt_proc_alive(sc->new_scp);
2276 /* sc->cur_scp == sc->new_scp */
2277 wakeup((caddr_t)&sc->cur_scp->smode);
2279 /* wait for the controlling process to acknowledge, if necessary */
2280 if (!signal_vt_acq(sc->cur_scp)) {
2281 sc->switch_in_progress = 0;
2282 if (sc->unit == sc_console_unit)
2283 cons_unavail = FALSE;
2290 vt_proc_alive(scr_stat *scp)
2293 if (scp->proc == pfind(scp->pid))
2296 scp->smode.mode = VT_AUTO;
2297 DPRINTF(5, ("vt controlling process %d died\n", scp->pid));
2303 signal_vt_rel(scr_stat *scp)
2305 if (scp->smode.mode != VT_PROCESS)
2307 scp->status |= SWITCH_WAIT_REL;
2308 psignal(scp->proc, scp->smode.relsig);
2309 DPRINTF(5, ("sending relsig to %d\n", scp->pid));
2314 signal_vt_acq(scr_stat *scp)
2316 if (scp->smode.mode != VT_PROCESS)
2318 if (scp->sc->unit == sc_console_unit)
2319 cons_unavail = TRUE;
2320 scp->status |= SWITCH_WAIT_ACQ;
2321 psignal(scp->proc, scp->smode.acqsig);
2322 DPRINTF(5, ("sending acqsig to %d\n", scp->pid));
2327 finish_vt_rel(scr_stat *scp, int release, int *s)
2329 if (scp == scp->sc->old_scp && scp->status & SWITCH_WAIT_REL) {
2330 scp->status &= ~SWITCH_WAIT_REL;
2332 *s = do_switch_scr(scp->sc, *s);
2334 scp->sc->switch_in_progress = 0;
2341 finish_vt_acq(scr_stat *scp)
2343 if (scp == scp->sc->new_scp && scp->status & SWITCH_WAIT_ACQ) {
2344 scp->status &= ~SWITCH_WAIT_ACQ;
2345 scp->sc->switch_in_progress = 0;
2352 exchange_scr(sc_softc_t *sc)
2356 /* save the current state of video and keyboard */
2357 sc_move_cursor(sc->old_scp, sc->old_scp->xpos, sc->old_scp->ypos);
2358 if (!ISGRAPHSC(sc->old_scp))
2359 sc_remove_cursor_image(sc->old_scp);
2360 if (sc->old_scp->kbd_mode == K_XLATE)
2361 save_kbd_state(sc->old_scp);
2363 /* set up the video for the new screen */
2364 scp = sc->cur_scp = sc->new_scp;
2365 if (sc->old_scp->mode != scp->mode || ISUNKNOWNSC(sc->old_scp))
2368 sc_vtb_init(&scp->scr, VTB_FRAMEBUFFER, scp->xsize, scp->ysize,
2369 (void *)sc->adp->va_window, FALSE);
2370 scp->status |= MOUSE_HIDDEN;
2371 sc_move_cursor(scp, scp->xpos, scp->ypos);
2372 if (!ISGRAPHSC(scp))
2373 sc_set_cursor_image(scp);
2374 #ifndef SC_NO_PALETTE_LOADING
2375 if (ISGRAPHSC(sc->old_scp))
2376 load_palette(sc->adp, sc->palette);
2378 sc_set_border(scp, scp->border);
2380 /* set up the keyboard for the new screen */
2381 if (sc->old_scp->kbd_mode != scp->kbd_mode)
2382 kbd_ioctl(sc->kbd, KDSKBMODE, (caddr_t)&scp->kbd_mode);
2383 update_kbd_state(scp, scp->status, LOCK_MASK);
2389 sc_puts(scr_stat *scp, u_char *buf, int len)
2392 /* make screensaver happy */
2393 if (!sticky_splash && scp == scp->sc->cur_scp)
2394 run_scrn_saver = FALSE;
2398 (*scp->tsw->te_puts)(scp, buf, len);
2400 if (scp->sc->delayed_next_scr)
2401 sc_switch_scr(scp->sc, scp->sc->delayed_next_scr - 1);
2405 sc_draw_cursor_image(scr_stat *scp)
2407 /* assert(scp == scp->sc->cur_scp); */
2408 ++scp->sc->videoio_in_progress;
2409 (*scp->rndr->draw_cursor)(scp, scp->cursor_pos,
2410 scp->sc->flags & SC_BLINK_CURSOR, TRUE,
2411 sc_inside_cutmark(scp, scp->cursor_pos));
2412 scp->cursor_oldpos = scp->cursor_pos;
2413 --scp->sc->videoio_in_progress;
2417 sc_remove_cursor_image(scr_stat *scp)
2419 /* assert(scp == scp->sc->cur_scp); */
2420 ++scp->sc->videoio_in_progress;
2421 (*scp->rndr->draw_cursor)(scp, scp->cursor_oldpos,
2422 scp->sc->flags & SC_BLINK_CURSOR, FALSE,
2423 sc_inside_cutmark(scp, scp->cursor_oldpos));
2424 --scp->sc->videoio_in_progress;
2428 update_cursor_image(scr_stat *scp)
2432 if (scp->sc->flags & SC_CHAR_CURSOR) {
2433 scp->cursor_base = imax(0, scp->sc->cursor_base);
2434 scp->cursor_height = imin(scp->sc->cursor_height, scp->font_size);
2436 scp->cursor_base = 0;
2437 scp->cursor_height = scp->font_size;
2439 blink = scp->sc->flags & SC_BLINK_CURSOR;
2441 /* assert(scp == scp->sc->cur_scp); */
2442 ++scp->sc->videoio_in_progress;
2443 (*scp->rndr->draw_cursor)(scp, scp->cursor_oldpos, blink, FALSE,
2444 sc_inside_cutmark(scp, scp->cursor_pos));
2445 (*scp->rndr->set_cursor)(scp, scp->cursor_base, scp->cursor_height, blink);
2446 (*scp->rndr->draw_cursor)(scp, scp->cursor_pos, blink, TRUE,
2447 sc_inside_cutmark(scp, scp->cursor_pos));
2448 --scp->sc->videoio_in_progress;
2452 sc_set_cursor_image(scr_stat *scp)
2454 if (scp->sc->flags & SC_CHAR_CURSOR) {
2455 scp->cursor_base = imax(0, scp->sc->cursor_base);
2456 scp->cursor_height = imin(scp->sc->cursor_height, scp->font_size);
2458 scp->cursor_base = 0;
2459 scp->cursor_height = scp->font_size;
2462 /* assert(scp == scp->sc->cur_scp); */
2463 ++scp->sc->videoio_in_progress;
2464 (*scp->rndr->set_cursor)(scp, scp->cursor_base, scp->cursor_height,
2465 scp->sc->flags & SC_BLINK_CURSOR);
2466 --scp->sc->videoio_in_progress;
2470 scinit(int unit, int flags)
2473 * When syscons is being initialized as the kernel console, malloc()
2474 * is not yet functional, because various kernel structures has not been
2475 * fully initialized yet. Therefore, we need to declare the following
2476 * static buffers for the console. This is less than ideal,
2477 * but is necessry evil for the time being. XXX
2479 static scr_stat main_console;
2480 static dev_t main_devs[MAXCONS];
2481 static struct tty main_tty;
2482 static u_short sc_buffer[ROW*COL]; /* XXX */
2483 #ifndef SC_NO_FONT_LOADING
2484 static u_char font_8[256*8];
2485 static u_char font_14[256*14];
2486 static u_char font_16[256*16];
2491 video_adapter_t *adp;
2496 /* one time initialization */
2497 if (init_done == COLD)
2498 sc_get_bios_values(&bios_value);
2502 * Allocate resources. Even if we are being called for the second
2503 * time, we must allocate them again, because they might have
2506 sc = sc_get_softc(unit, flags & SC_KERNEL_CONSOLE);
2508 if (sc->adapter >= 0) {
2509 vid_release(sc->adp, (void *)&sc->adapter);
2513 if (sc->keyboard >= 0) {
2514 DPRINTF(5, ("sc%d: releasing kbd%d\n", unit, sc->keyboard));
2515 i = kbd_release(sc->kbd, (void *)&sc->keyboard);
2516 DPRINTF(5, ("sc%d: kbd_release returned %d\n", unit, i));
2517 if (sc->kbd != NULL) {
2518 DPRINTF(5, ("sc%d: kbd != NULL!, index:%d, unit:%d, flags:0x%x\n",
2519 unit, sc->kbd->kb_index, sc->kbd->kb_unit, sc->kbd->kb_flags));
2523 sc->adapter = vid_allocate("*", unit, (void *)&sc->adapter);
2524 sc->adp = vid_get_adapter(sc->adapter);
2525 /* assert((sc->adapter >= 0) && (sc->adp != NULL)) */
2526 sc->keyboard = kbd_allocate("*", unit, (void *)&sc->keyboard,
2528 DPRINTF(1, ("sc%d: keyboard %d\n", unit, sc->keyboard));
2529 sc->kbd = kbd_get_keyboard(sc->keyboard);
2530 if (sc->kbd != NULL) {
2531 DPRINTF(1, ("sc%d: kbd index:%d, unit:%d, flags:0x%x\n",
2532 unit, sc->kbd->kb_index, sc->kbd->kb_unit, sc->kbd->kb_flags));
2535 if (!(sc->flags & SC_INIT_DONE) || (adp != sc->adp)) {
2537 sc->initial_mode = sc->adp->va_initial_mode;
2539 #ifndef SC_NO_FONT_LOADING
2540 if (flags & SC_KERNEL_CONSOLE) {
2541 sc->font_8 = font_8;
2542 sc->font_14 = font_14;
2543 sc->font_16 = font_16;
2544 } else if (sc->font_8 == NULL) {
2545 /* assert(sc_malloc) */
2546 sc->font_8 = malloc(sizeof(font_8), M_DEVBUF, M_WAITOK);
2547 sc->font_14 = malloc(sizeof(font_14), M_DEVBUF, M_WAITOK);
2548 sc->font_16 = malloc(sizeof(font_16), M_DEVBUF, M_WAITOK);
2552 /* extract the hardware cursor location and hide the cursor for now */
2553 (*vidsw[sc->adapter]->read_hw_cursor)(sc->adp, &col, &row);
2554 (*vidsw[sc->adapter]->set_hw_cursor)(sc->adp, -1, -1);
2556 /* set up the first console */
2557 sc->first_vty = unit*MAXCONS;
2558 sc->vtys = MAXCONS; /* XXX: should be configurable */
2559 if (flags & SC_KERNEL_CONSOLE) {
2560 sc->dev = main_devs;
2561 sc->dev[0] = makedev(CDEV_MAJOR, unit*MAXCONS);
2562 sc->dev[0]->si_tty = &main_tty;
2563 ttyregister(&main_tty);
2564 scp = &main_console;
2565 init_scp(sc, sc->first_vty, scp);
2566 sc_vtb_init(&scp->vtb, VTB_MEMORY, scp->xsize, scp->ysize,
2567 (void *)sc_buffer, FALSE);
2568 if (sc_init_emulator(scp, SC_DFLT_TERM))
2569 sc_init_emulator(scp, "*");
2570 (*scp->tsw->te_default_attr)(scp,
2571 kernel_default.std_color,
2572 kernel_default.rev_color);
2574 /* assert(sc_malloc) */
2575 sc->dev = malloc(sizeof(dev_t)*sc->vtys, M_DEVBUF, M_WAITOK);
2576 bzero(sc->dev, sizeof(dev_t)*sc->vtys);
2577 sc->dev[0] = makedev(CDEV_MAJOR, unit*MAXCONS);
2578 sc->dev[0]->si_tty = ttymalloc(sc->dev[0]->si_tty);
2579 scp = alloc_scp(sc, sc->first_vty);
2581 SC_STAT(sc->dev[0]) = scp;
2584 /* copy screen to temporary buffer */
2585 sc_vtb_init(&scp->scr, VTB_FRAMEBUFFER, scp->xsize, scp->ysize,
2586 (void *)scp->sc->adp->va_window, FALSE);
2588 sc_vtb_copy(&scp->scr, 0, &scp->vtb, 0, scp->xsize*scp->ysize);
2590 /* move cursors to the initial positions */
2591 if (col >= scp->xsize)
2593 if (row >= scp->ysize)
2594 row = scp->ysize - 1;
2597 scp->cursor_pos = scp->cursor_oldpos = row*scp->xsize + col;
2598 if (bios_value.cursor_end < scp->font_size)
2599 sc->cursor_base = scp->font_size - bios_value.cursor_end - 1;
2601 sc->cursor_base = 0;
2602 i = bios_value.cursor_end - bios_value.cursor_start + 1;
2603 sc->cursor_height = imin(i, scp->font_size);
2604 #ifndef SC_NO_SYSMOUSE
2605 sc_mouse_move(scp, scp->xpixel/2, scp->ypixel/2);
2607 if (!ISGRAPHSC(scp)) {
2608 sc_set_cursor_image(scp);
2609 sc_draw_cursor_image(scp);
2612 /* save font and palette */
2613 #ifndef SC_NO_FONT_LOADING
2614 sc->fonts_loaded = 0;
2615 if (ISFONTAVAIL(sc->adp->va_flags)) {
2617 bcopy(dflt_font_8, sc->font_8, sizeof(dflt_font_8));
2618 bcopy(dflt_font_14, sc->font_14, sizeof(dflt_font_14));
2619 bcopy(dflt_font_16, sc->font_16, sizeof(dflt_font_16));
2620 sc->fonts_loaded = FONT_16 | FONT_14 | FONT_8;
2621 if (scp->font_size < 14) {
2622 sc_load_font(scp, 0, 8, sc->font_8, 0, 256);
2623 } else if (scp->font_size >= 16) {
2624 sc_load_font(scp, 0, 16, sc->font_16, 0, 256);
2626 sc_load_font(scp, 0, 14, sc->font_14, 0, 256);
2628 #else /* !SC_DFLT_FONT */
2629 if (scp->font_size < 14) {
2630 sc_save_font(scp, 0, 8, sc->font_8, 0, 256);
2631 sc->fonts_loaded = FONT_8;
2632 } else if (scp->font_size >= 16) {
2633 sc_save_font(scp, 0, 16, sc->font_16, 0, 256);
2634 sc->fonts_loaded = FONT_16;
2636 sc_save_font(scp, 0, 14, sc->font_14, 0, 256);
2637 sc->fonts_loaded = FONT_14;
2639 #endif /* SC_DFLT_FONT */
2640 /* FONT KLUDGE: always use the font page #0. XXX */
2641 sc_show_font(scp, 0);
2643 #endif /* !SC_NO_FONT_LOADING */
2645 #ifndef SC_NO_PALETTE_LOADING
2646 save_palette(sc->adp, sc->palette);
2650 if (!(sc->flags & SC_SPLASH_SCRN) && (flags & SC_KERNEL_CONSOLE)) {
2651 /* we are ready to put up the splash image! */
2652 splash_init(sc->adp, scsplash_callback, sc);
2653 sc->flags |= SC_SPLASH_SCRN;
2655 #endif /* NSPLASH */
2658 /* the rest is not necessary, if we have done it once */
2659 if (sc->flags & SC_INIT_DONE)
2662 /* initialize mapscrn arrays to a one to one map */
2663 for (i = 0; i < sizeof(sc->scr_map); i++)
2664 sc->scr_map[i] = sc->scr_rmap[i] = i;
2666 sc->flags |= SC_INIT_DONE;
2671 scterm(int unit, int flags)
2676 sc = sc_get_softc(unit, flags & SC_KERNEL_CONSOLE);
2678 return; /* shouldn't happen */
2681 /* this console is no longer available for the splash screen */
2682 if (sc->flags & SC_SPLASH_SCRN) {
2683 splash_term(sc->adp);
2684 sc->flags &= ~SC_SPLASH_SCRN;
2686 #endif /* NSPLASH */
2689 /* move the hardware cursor to the upper-left corner */
2690 (*vidsw[sc->adapter]->set_hw_cursor)(sc->adp, 0, 0);
2693 /* release the keyboard and the video card */
2694 if (sc->keyboard >= 0)
2695 kbd_release(sc->kbd, &sc->keyboard);
2696 if (sc->adapter >= 0)
2697 vid_release(sc->adp, &sc->adapter);
2699 /* stop the terminal emulator, if any */
2700 scp = SC_STAT(sc->dev[0]);
2702 (*scp->tsw->te_term)(scp, &scp->ts);
2703 if (scp->ts != NULL)
2704 free(scp->ts, M_DEVBUF);
2706 /* clear the structure */
2707 if (!(flags & SC_KERNEL_CONSOLE)) {
2708 /* XXX: We need delete_dev() for this */
2709 free(sc->dev, M_DEVBUF);
2711 /* XXX: We need a ttyunregister for this */
2712 free(sc->tty, M_DEVBUF);
2714 #ifndef SC_NO_FONT_LOADING
2715 free(sc->font_8, M_DEVBUF);
2716 free(sc->font_14, M_DEVBUF);
2717 free(sc->font_16, M_DEVBUF);
2719 /* XXX vtb, history */
2721 bzero(sc, sizeof(*sc));
2728 scshutdown(void *arg, int howto)
2730 /* assert(sc_console != NULL) */
2732 sc_touch_scrn_saver();
2733 if (!cold && sc_console
2734 && sc_console->sc->cur_scp->smode.mode == VT_AUTO
2735 && sc_console->smode.mode == VT_AUTO)
2736 sc_switch_scr(sc_console->sc, sc_console->index);
2737 shutdown_in_progress = TRUE;
2741 sc_clean_up(scr_stat *scp)
2745 #endif /* NSPLASH */
2747 if (scp->sc->flags & SC_SCRN_BLANKED) {
2748 sc_touch_scrn_saver();
2750 if ((error = wait_scrn_saver_stop(scp->sc)))
2752 #endif /* NSPLASH */
2754 scp->status |= MOUSE_HIDDEN;
2755 sc_remove_mouse_image(scp);
2756 sc_remove_cutmarking(scp);
2761 sc_alloc_scr_buffer(scr_stat *scp, int wait, int discard)
2767 sc_vtb_init(&new, VTB_MEMORY, scp->xsize, scp->ysize, NULL, wait);
2768 if (!discard && (old.vtb_flags & VTB_VALID)) {
2769 /* retain the current cursor position and buffer contants */
2770 scp->cursor_oldpos = scp->cursor_pos;
2772 * This works only if the old buffer has the same size as or larger
2773 * than the new one. XXX
2775 sc_vtb_copy(&old, 0, &new, 0, scp->xsize*scp->ysize);
2779 sc_vtb_destroy(&old);
2782 #ifndef SC_NO_SYSMOUSE
2783 /* move the mouse cursor at the center of the screen */
2784 sc_mouse_move(scp, scp->xpixel / 2, scp->ypixel / 2);
2789 *alloc_scp(sc_softc_t *sc, int vty)
2793 /* assert(sc_malloc) */
2795 scp = (scr_stat *)malloc(sizeof(scr_stat), M_DEVBUF, M_WAITOK);
2796 init_scp(sc, vty, scp);
2798 sc_alloc_scr_buffer(scp, TRUE, TRUE);
2799 if (sc_init_emulator(scp, SC_DFLT_TERM))
2800 sc_init_emulator(scp, "*");
2802 #ifndef SC_NO_CUTPASTE
2803 sc_alloc_cut_buffer(scp, TRUE);
2806 #ifndef SC_NO_HISTORY
2807 sc_alloc_history_buffer(scp, 0, 0, TRUE);
2814 init_scp(sc_softc_t *sc, int vty, scr_stat *scp)
2818 bzero(scp, sizeof(*scp));
2823 scp->mode = sc->initial_mode;
2824 (*vidsw[sc->adapter]->get_info)(sc->adp, scp->mode, &info);
2825 if (info.vi_flags & V_INFO_GRAPHICS) {
2826 scp->status |= GRAPHICS_MODE;
2827 scp->xpixel = info.vi_width;
2828 scp->ypixel = info.vi_height;
2829 scp->xsize = info.vi_width/8;
2830 scp->ysize = info.vi_height/info.vi_cheight;
2834 scp->xsize = info.vi_width;
2835 scp->ysize = info.vi_height;
2836 scp->xpixel = scp->xsize*8;
2837 scp->ypixel = scp->ysize*info.vi_cheight;
2838 if (info.vi_cheight < 14) {
2840 #ifndef SC_NO_FONT_LOADING
2841 scp->font = sc->font_8;
2845 } else if (info.vi_cheight >= 16) {
2846 scp->font_size = 16;
2847 #ifndef SC_NO_FONT_LOADING
2848 scp->font = sc->font_16;
2853 scp->font_size = 14;
2854 #ifndef SC_NO_FONT_LOADING
2855 scp->font = sc->font_14;
2861 sc_vtb_init(&scp->vtb, VTB_MEMORY, 0, 0, NULL, FALSE);
2862 sc_vtb_init(&scp->scr, VTB_FRAMEBUFFER, 0, 0, NULL, FALSE);
2863 scp->xoff = scp->yoff = 0;
2864 scp->xpos = scp->ypos = 0;
2865 scp->start = scp->xsize * scp->ysize - 1;
2870 scp->border = BG_BLACK;
2871 scp->cursor_base = sc->cursor_base;
2872 scp->cursor_height = imin(sc->cursor_height, scp->font_size);
2873 scp->mouse_cut_start = scp->xsize*scp->ysize;
2874 scp->mouse_cut_end = -1;
2875 scp->mouse_signal = 0;
2877 scp->mouse_proc = NULL;
2878 scp->kbd_mode = K_XLATE;
2879 scp->bell_pitch = bios_value.bell_pitch;
2880 scp->bell_duration = BELL_DURATION;
2881 scp->status |= (bios_value.shift_state & NLKED);
2882 scp->status |= CURSOR_ENABLED | MOUSE_HIDDEN;
2885 scp->smode.mode = VT_AUTO;
2886 scp->history = NULL;
2887 scp->history_pos = 0;
2888 scp->history_size = 0;
2892 sc_init_emulator(scr_stat *scp, char *name)
2899 if (name == NULL) /* if no name is given, use the current emulator */
2901 else /* ...otherwise find the named emulator */
2902 sw = sc_term_match(name);
2907 if (strcmp(sw->te_renderer, "*") != 0) {
2908 rndr = sc_render_match(scp, sw->te_renderer,
2909 scp->status & (GRAPHICS_MODE | PIXEL_MODE));
2912 rndr = sc_render_match(scp, scp->sc->adp->va_name,
2913 scp->status & (GRAPHICS_MODE | PIXEL_MODE));
2918 if (sw == scp->tsw) {
2919 error = (*sw->te_init)(scp, &scp->ts, SC_TE_WARM_INIT);
2921 sc_clear_screen(scp);
2922 /* assert(error == 0); */
2926 if (sc_malloc && (sw->te_size > 0))
2927 p = malloc(sw->te_size, M_DEVBUF, M_NOWAIT);
2930 error = (*sw->te_init)(scp, &p, SC_TE_COLD_INIT);
2935 (*scp->tsw->te_term)(scp, &scp->ts);
2936 if (scp->ts != NULL)
2937 free(scp->ts, M_DEVBUF);
2943 (*sw->te_default_attr)(scp, user_default.std_color, user_default.rev_color);
2944 sc_clear_screen(scp);
2950 * scgetc(flags) - get character from keyboard.
2951 * If flags & SCGETC_CN, then avoid harmful side effects.
2952 * If flags & SCGETC_NONBLOCK, then wait until a key is pressed, else
2953 * return NOKEY if there is nothing there.
2956 scgetc(sc_softc_t *sc, u_int flags)
2959 #ifndef SC_NO_HISTORY
2967 if (sc->kbd == NULL)
2972 /* I don't like this, but... XXX */
2973 if (flags & SCGETC_CN)
2974 sccnupdate(sc->cur_scp);
2977 /* first see if there is something in the keyboard port */
2979 c = kbd_read_char(sc->kbd, !(flags & SCGETC_NONBLOCK));
2981 if (!(flags & SCGETC_CN))
2982 sc_bell(scp, bios_value.bell_pitch, BELL_DURATION);
2983 } else if (c == NOKEY)
2989 /* make screensaver happy */
2991 sc_touch_scrn_saver();
2994 if (!(flags & SCGETC_CN))
2995 /* do the /dev/random device a favour */
2996 add_keyboard_randomness(c);
2999 if (scp->kbd_mode != K_XLATE)
3002 /* if scroll-lock pressed allow history browsing */
3003 if (!ISGRAPHSC(scp) && scp->history && scp->status & SLKED) {
3005 scp->status &= ~CURSOR_ENABLED;
3006 sc_remove_cursor_image(scp);
3008 #ifndef SC_NO_HISTORY
3009 if (!(scp->status & BUFFER_SAVED)) {
3010 scp->status |= BUFFER_SAVED;
3014 /* FIXME: key codes */
3015 case SPCLKEY | FKEY | F(49): /* home key */
3016 sc_remove_cutmarking(scp);
3020 case SPCLKEY | FKEY | F(57): /* end key */
3021 sc_remove_cutmarking(scp);
3025 case SPCLKEY | FKEY | F(50): /* up arrow key */
3026 sc_remove_cutmarking(scp);
3027 if (sc_hist_up_line(scp))
3028 if (!(flags & SCGETC_CN))
3029 sc_bell(scp, bios_value.bell_pitch, BELL_DURATION);
3032 case SPCLKEY | FKEY | F(58): /* down arrow key */
3033 sc_remove_cutmarking(scp);
3034 if (sc_hist_down_line(scp))
3035 if (!(flags & SCGETC_CN))
3036 sc_bell(scp, bios_value.bell_pitch, BELL_DURATION);
3039 case SPCLKEY | FKEY | F(51): /* page up key */
3040 sc_remove_cutmarking(scp);
3041 for (i=0; i<scp->ysize; i++)
3042 if (sc_hist_up_line(scp)) {
3043 if (!(flags & SCGETC_CN))
3044 sc_bell(scp, bios_value.bell_pitch, BELL_DURATION);
3049 case SPCLKEY | FKEY | F(59): /* page down key */
3050 sc_remove_cutmarking(scp);
3051 for (i=0; i<scp->ysize; i++)
3052 if (sc_hist_down_line(scp)) {
3053 if (!(flags & SCGETC_CN))
3054 sc_bell(scp, bios_value.bell_pitch, BELL_DURATION);
3059 #endif /* SC_NO_HISTORY */
3063 * Process and consume special keys here. Return a plain char code
3064 * or a char code with the META flag or a function key code.
3068 /* goto next_code */
3073 switch (KEYCHAR(c)) {
3075 case NLK: case CLK: case ALK:
3078 kbd_ioctl(sc->kbd, KDGKBSTATE, (caddr_t)&f);
3080 scp->status |= SLKED;
3082 if (scp->status & SLKED) {
3083 scp->status &= ~SLKED;
3084 #ifndef SC_NO_HISTORY
3085 if (scp->status & BUFFER_SAVED) {
3086 if (!sc_hist_restore(scp))
3087 sc_remove_cutmarking(scp);
3088 scp->status &= ~BUFFER_SAVED;
3089 scp->status |= CURSOR_ENABLED;
3090 sc_draw_cursor_image(scp);
3092 tp = VIRTUAL_TTY(sc, scp->index);
3100 /* NON-LOCKING KEYS */
3102 case LSH: case RSH: case LCTR: case RCTR:
3103 case LALT: case RALT: case ASH: case META:
3107 if (!(sc->flags & SC_SCRN_BLANKED))
3113 /* force activatation/deactivation of the screen saver */
3114 if (!(sc->flags & SC_SCRN_BLANKED)) {
3115 run_scrn_saver = TRUE;
3116 sc->scrn_time_stamp -= scrn_blank_time;
3120 * While devices are being probed, the screen saver need
3121 * to be invoked explictly. XXX
3123 if (sc->flags & SC_SCRN_BLANKED) {
3124 scsplash_stick(FALSE);
3125 stop_scrn_saver(sc, current_saver);
3127 if (!ISGRAPHSC(scp)) {
3128 scsplash_stick(TRUE);
3129 (*current_saver)(sc, TRUE);
3133 #endif /* NSPLASH */
3137 #ifndef SC_DISABLE_REBOOT
3143 #ifndef SC_DISABLE_REBOOT
3144 shutdown_nice(RB_HALT);
3149 #ifndef SC_DISABLE_REBOOT
3150 shutdown_nice(RB_HALT|RB_POWEROFF);
3156 apm_suspend(PMST_SUSPEND);
3159 apm_suspend(PMST_STANDBY);
3168 #ifndef SC_DISABLE_DDBKEY
3170 Debugger("manual escape to debugger");
3172 printf("No debugger in kernel\n");
3174 #else /* SC_DISABLE_DDBKEY */
3176 #endif /* SC_DISABLE_DDBKEY */
3180 if (enable_panic_key)
3181 panic("Forced by the panic key");
3185 this_scr = scp->index;
3186 for (i = (this_scr - sc->first_vty + 1)%sc->vtys;
3187 sc->first_vty + i != this_scr;
3188 i = (i + 1)%sc->vtys) {
3189 struct tty *tp = VIRTUAL_TTY(sc, sc->first_vty + i);
3190 if (ISTTYOPEN(tp)) {
3191 sc_switch_scr(scp->sc, sc->first_vty + i);
3198 this_scr = scp->index;
3199 for (i = (this_scr - sc->first_vty + sc->vtys - 1)%sc->vtys;
3200 sc->first_vty + i != this_scr;
3201 i = (i + sc->vtys - 1)%sc->vtys) {
3202 struct tty *tp = VIRTUAL_TTY(sc, sc->first_vty + i);
3203 if (ISTTYOPEN(tp)) {
3204 sc_switch_scr(scp->sc, sc->first_vty + i);
3211 if (KEYCHAR(c) >= F_SCR && KEYCHAR(c) <= L_SCR) {
3212 sc_switch_scr(scp->sc, sc->first_vty + KEYCHAR(c) - F_SCR);
3215 /* assert(c & FKEY) */
3216 if (!(sc->flags & SC_SCRN_BLANKED))
3220 /* goto next_code */
3222 /* regular keys (maybe MKEY is set) */
3223 if (!(sc->flags & SC_SCRN_BLANKED))
3232 scmmap(dev_t dev, vm_offset_t offset, int nprot)
3237 if (scp != scp->sc->cur_scp)
3239 return (*vidsw[scp->sc->adapter]->mmap)(scp->sc->adp, offset, nprot);
3243 save_kbd_state(scr_stat *scp)
3248 error = kbd_ioctl(scp->sc->kbd, KDGKBSTATE, (caddr_t)&state);
3249 if (error == ENOIOCTL)
3252 scp->status &= ~LOCK_MASK;
3253 scp->status |= state;
3259 update_kbd_state(scr_stat *scp, int new_bits, int mask)
3264 if (mask != LOCK_MASK) {
3265 error = kbd_ioctl(scp->sc->kbd, KDGKBSTATE, (caddr_t)&state);
3266 if (error == ENOIOCTL)
3271 state |= new_bits & mask;
3273 state = new_bits & LOCK_MASK;
3275 error = kbd_ioctl(scp->sc->kbd, KDSKBSTATE, (caddr_t)&state);
3276 if (error == ENOIOCTL)
3282 update_kbd_leds(scr_stat *scp, int which)
3287 error = kbd_ioctl(scp->sc->kbd, KDSETLED, (caddr_t)&which);
3288 if (error == ENOIOCTL)
3294 set_mode(scr_stat *scp)
3298 /* reject unsupported mode */
3299 if ((*vidsw[scp->sc->adapter]->get_info)(scp->sc->adp, scp->mode, &info))
3302 /* if this vty is not currently showing, do nothing */
3303 if (scp != scp->sc->cur_scp)
3306 /* setup video hardware for the given mode */
3307 (*vidsw[scp->sc->adapter]->set_mode)(scp->sc->adp, scp->mode);
3308 sc_vtb_init(&scp->scr, VTB_FRAMEBUFFER, scp->xsize, scp->ysize,
3309 (void *)scp->sc->adp->va_window, FALSE);
3311 #ifndef SC_NO_FONT_LOADING
3312 /* load appropriate font */
3313 if (!(scp->status & GRAPHICS_MODE)) {
3314 if (!(scp->status & PIXEL_MODE) && ISFONTAVAIL(scp->sc->adp->va_flags)) {
3315 if (scp->font_size < 14) {
3316 if (scp->sc->fonts_loaded & FONT_8)
3317 sc_load_font(scp, 0, 8, scp->sc->font_8, 0, 256);
3318 } else if (scp->font_size >= 16) {
3319 if (scp->sc->fonts_loaded & FONT_16)
3320 sc_load_font(scp, 0, 16, scp->sc->font_16, 0, 256);
3322 if (scp->sc->fonts_loaded & FONT_14)
3323 sc_load_font(scp, 0, 14, scp->sc->font_14, 0, 256);
3327 * This is an interim kludge to display correct font.
3328 * Always use the font page #0 on the video plane 2.
3329 * Somehow we cannot show the font in other font pages on
3330 * some video cards... XXX
3332 sc_show_font(scp, 0);
3336 #endif /* !SC_NO_FONT_LOADING */
3338 sc_set_border(scp, scp->border);
3339 sc_set_cursor_image(scp);
3345 sc_set_border(scr_stat *scp, int color)
3347 ++scp->sc->videoio_in_progress;
3348 (*scp->rndr->draw_border)(scp, color);
3349 --scp->sc->videoio_in_progress;
3352 #ifndef SC_NO_FONT_LOADING
3354 sc_load_font(scr_stat *scp, int page, int size, u_char *buf,
3355 int base, int count)
3360 sc->font_loading_in_progress = TRUE;
3361 (*vidsw[sc->adapter]->load_font)(sc->adp, page, size, buf, base, count);
3362 sc->font_loading_in_progress = FALSE;
3366 sc_save_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]->save_font)(sc->adp, page, size, buf, base, count);
3374 sc->font_loading_in_progress = FALSE;
3378 sc_show_font(scr_stat *scp, int page)
3380 (*vidsw[scp->sc->adapter]->show_font)(scp->sc->adp, page);
3382 #endif /* !SC_NO_FONT_LOADING */
3385 sc_paste(scr_stat *scp, u_char *p, int count)
3390 if (scp->status & MOUSE_VISIBLE) {
3391 tp = VIRTUAL_TTY(scp->sc, scp->sc->cur_scp->index);
3394 rmap = scp->sc->scr_rmap;
3395 for (; count > 0; --count)
3396 (*linesw[tp->t_line].l_rint)(rmap[*p++], tp);
3401 sc_bell(scr_stat *scp, int pitch, int duration)
3403 if (cold || shutdown_in_progress)
3406 if (scp != scp->sc->cur_scp && (scp->sc->flags & SC_QUIET_BELL))
3409 if (scp->sc->flags & SC_VISUAL_BELL) {
3410 if (scp->sc->blink_in_progress)
3412 scp->sc->blink_in_progress = 3;
3413 if (scp != scp->sc->cur_scp)
3414 scp->sc->blink_in_progress += 2;
3415 blink_screen(scp->sc->cur_scp);
3417 if (scp != scp->sc->cur_scp)
3419 sysbeep(pitch, duration);
3424 blink_screen(void *arg)
3426 scr_stat *scp = arg;
3429 if (ISGRAPHSC(scp) || (scp->sc->blink_in_progress <= 1)) {
3430 scp->sc->blink_in_progress = 0;
3432 tp = VIRTUAL_TTY(scp->sc, scp->index);
3435 if (scp->sc->delayed_next_scr)
3436 sc_switch_scr(scp->sc, scp->sc->delayed_next_scr - 1);
3439 (*scp->rndr->draw)(scp, 0, scp->xsize*scp->ysize,
3440 scp->sc->blink_in_progress & 1);
3441 scp->sc->blink_in_progress--;
3442 timeout(blink_screen, scp, hz / 10);