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.
31 #include "opt_syscons.h"
32 #include "opt_splash.h"
35 #include <sys/param.h>
36 #include <sys/systm.h>
39 #include <sys/consio.h>
40 #include <sys/eventhandler.h>
43 #include <sys/kernel.h>
45 #include <sys/malloc.h>
46 #include <sys/mutex.h>
48 #include <sys/random.h>
49 #include <sys/reboot.h>
50 #include <sys/signalvar.h>
51 #include <sys/sysctl.h>
53 #include <sys/power.h>
55 #include <machine/clock.h>
56 #include <machine/pc/display.h>
58 #include <machine/psl.h>
59 #include <machine/apm_bios.h>
60 #include <machine/frame.h>
63 #include <dev/kbd/kbdreg.h>
64 #include <dev/fb/fbreg.h>
65 #include <dev/fb/splashreg.h>
66 #include <dev/syscons/syscons.h>
71 #define DEFAULT_BLANKTIME (5*60) /* 5 minutes */
72 #define MAX_BLANKTIME (7*24*60*60) /* 7 days!? */
74 #define KEYCODE_BS 0x0e /* "<-- Backspace" key, XXX */
76 typedef struct default_attr {
77 int std_color; /* normal hardware color */
78 int rev_color; /* reverse hardware color */
81 static default_attr user_default = {
86 static default_attr kernel_default = {
88 SC_KERNEL_CONS_REV_ATTR,
91 static int sc_console_unit = -1;
92 static int sc_saver_keyb_only = 1;
93 static scr_stat *sc_console;
94 static struct tty *sc_console_tty;
95 static void *kernel_console_ts;
97 static char init_done = COLD;
98 static char shutdown_in_progress = FALSE;
99 static char sc_malloc = FALSE;
101 static int saver_mode = CONS_NO_SAVER; /* LKM/user saver */
102 static int run_scrn_saver = FALSE; /* should run the saver? */
103 static long scrn_blank_time = 0; /* screen saver timeout value */
105 static int scrn_blanked; /* # of blanked screen */
106 static int sticky_splash = FALSE;
108 static void none_saver(sc_softc_t *sc, int blank) { }
109 static void (*current_saver)(sc_softc_t *, int) = none_saver;
112 SYSCTL_NODE(_hw, OID_AUTO, syscons, CTLFLAG_RD, 0, "syscons");
113 SYSCTL_NODE(_hw_syscons, OID_AUTO, saver, CTLFLAG_RD, 0, "saver");
114 SYSCTL_INT(_hw_syscons_saver, OID_AUTO, keybonly, CTLFLAG_RW,
115 &sc_saver_keyb_only, 0, "screen saver interrupted by input only");
116 #if !defined(SC_NO_FONT_LOADING) && defined(SC_DFLT_FONT)
120 d_ioctl_t *sc_user_ioctl;
122 static bios_values_t bios_value;
124 static int enable_panic_key;
125 SYSCTL_INT(_machdep, OID_AUTO, enable_panic_key, CTLFLAG_RW, &enable_panic_key,
128 #define SC_CONSOLECTL 255
130 #define VIRTUAL_TTY(sc, x) (SC_DEV((sc), (x)) != NULL ? \
131 SC_DEV((sc), (x))->si_tty : NULL)
132 #define ISTTYOPEN(tp) ((tp) && ((tp)->t_state & TS_ISOPEN))
137 static int scvidprobe(int unit, int flags, int cons);
138 static int sckbdprobe(int unit, int flags, int cons);
139 static void scmeminit(void *arg);
140 static int scdevtounit(dev_t dev);
141 static kbd_callback_func_t sckbdevent;
142 static int scparam(struct tty *tp, struct termios *t);
143 static void scstart(struct tty *tp);
144 static void scinit(int unit, int flags);
145 #if __i386__ || __ia64__
146 static void scterm(int unit, int flags);
148 static void scshutdown(void *arg, int howto);
149 static u_int scgetc(sc_softc_t *sc, u_int flags);
151 #define SCGETC_NONBLOCK 2
152 static int sccngetch(int flags);
153 static void sccnupdate(scr_stat *scp);
154 static scr_stat *alloc_scp(sc_softc_t *sc, int vty);
155 static void init_scp(sc_softc_t *sc, int vty, scr_stat *scp);
156 static timeout_t scrn_timer;
157 static int and_region(int *s1, int *e1, int s2, int e2);
158 static void scrn_update(scr_stat *scp, int show_cursor);
161 static int scsplash_callback(int event, void *arg);
162 static void scsplash_saver(sc_softc_t *sc, int show);
163 static int add_scrn_saver(void (*this_saver)(sc_softc_t *, int));
164 static int remove_scrn_saver(void (*this_saver)(sc_softc_t *, int));
165 static int set_scrn_saver_mode(scr_stat *scp, int mode, u_char *pal, int border);
166 static int restore_scrn_saver_mode(scr_stat *scp, int changemode);
167 static void stop_scrn_saver(sc_softc_t *sc, void (*saver)(sc_softc_t *, int));
168 static int wait_scrn_saver_stop(sc_softc_t *sc);
169 #define scsplash_stick(stick) (sticky_splash = (stick))
170 #else /* !DEV_SPLASH */
171 #define scsplash_stick(stick)
172 #endif /* DEV_SPLASH */
174 static int do_switch_scr(sc_softc_t *sc, int s);
175 static int vt_proc_alive(scr_stat *scp);
176 static int signal_vt_rel(scr_stat *scp);
177 static int signal_vt_acq(scr_stat *scp);
178 static int finish_vt_rel(scr_stat *scp, int release, int *s);
179 static int finish_vt_acq(scr_stat *scp);
180 static void exchange_scr(sc_softc_t *sc);
181 static void update_cursor_image(scr_stat *scp);
182 static void change_cursor_shape(scr_stat *scp, int flags, int base, int height);
183 static int save_kbd_state(scr_stat *scp);
184 static int update_kbd_state(scr_stat *scp, int state, int mask);
185 static int update_kbd_leds(scr_stat *scp, int which);
186 static timeout_t blink_screen;
188 #define CDEV_MAJOR 12
190 static cn_probe_t sccnprobe;
191 static cn_init_t sccninit;
192 static cn_getc_t sccngetc;
193 static cn_checkc_t sccncheckc;
194 static cn_putc_t sccnputc;
195 static cn_dbctl_t sccndbctl;
196 static cn_term_t sccnterm;
199 void sccnattach(void);
202 CONS_DRIVER(sc, sccnprobe, sccninit, sccnterm, sccngetc, sccncheckc, sccnputc,
205 static d_open_t scopen;
206 static d_close_t scclose;
207 static d_read_t scread;
208 static d_ioctl_t scioctl;
209 static d_mmap_t scmmap;
211 static struct cdevsw sc_cdevsw = {
215 /* write */ ttywrite,
219 /* strategy */ nostrategy,
221 /* maj */ CDEV_MAJOR,
228 sc_probe_unit(int unit, int flags)
230 if (!scvidprobe(unit, flags, FALSE)) {
232 printf("sc%d: no video adapter found.\n", unit);
236 /* syscons will be attached even when there is no keyboard */
237 sckbdprobe(unit, flags, FALSE);
242 /* probe video adapters, return TRUE if found */
244 scvidprobe(int unit, int flags, int cons)
247 * Access the video adapter driver through the back door!
248 * Video adapter drivers need to be configured before syscons.
249 * However, when syscons is being probed as the low-level console,
250 * they have not been initialized yet. We force them to initialize
251 * themselves here. XXX
253 vid_configure(cons ? VIO_PROBE_ONLY : 0);
255 return (vid_find_adapter("*", unit) >= 0);
258 /* probe the keyboard, return TRUE if found */
260 sckbdprobe(int unit, int flags, int cons)
262 /* access the keyboard driver through the backdoor! */
263 kbd_configure(cons ? KB_CONF_PROBE_ONLY : 0);
265 return (kbd_find_keyboard("*", unit) >= 0);
269 *adapter_name(video_adapter_t *adp)
275 { KD_MONO, { "MDA", "MDA" } },
276 { KD_HERCULES, { "Hercules", "Hercules" } },
277 { KD_CGA, { "CGA", "CGA" } },
278 { KD_EGA, { "EGA", "EGA (mono)" } },
279 { KD_VGA, { "VGA", "VGA (mono)" } },
280 { KD_PC98, { "PC-98x1", "PC-98x1" } },
281 { KD_TGA, { "TGA", "TGA" } },
282 { -1, { "Unknown", "Unknown" } },
286 for (i = 0; names[i].type != -1; ++i)
287 if (names[i].type == adp->va_type)
289 return names[i].name[(adp->va_flags & V_ADP_COLOR) ? 0 : 1];
293 sc_attach_unit(int unit, int flags)
303 flags &= ~SC_KERNEL_CONSOLE;
305 if (sc_console_unit == unit) {
307 * If this unit is being used as the system console, we need to
308 * adjust some variables and buffers before and after scinit().
310 /* assert(sc_console != NULL) */
311 flags |= SC_KERNEL_CONSOLE;
316 if (sc_console->tsw->te_size > 0) {
317 /* assert(sc_console->ts != NULL); */
318 kernel_console_ts = sc_console->ts;
319 sc_console->ts = malloc(sc_console->tsw->te_size,
321 bcopy(kernel_console_ts, sc_console->ts, sc_console->tsw->te_size);
322 (*sc_console->tsw->te_default_attr)(sc_console,
323 user_default.std_color,
324 user_default.rev_color);
330 sc = sc_get_softc(unit, flags & SC_KERNEL_CONSOLE);
332 scp = SC_STAT(sc->dev[0]);
333 if (sc_console == NULL) /* sc_console_unit < 0 */
337 if ((sc->config & SC_VESA800X600)
338 && ((*vidsw[sc->adapter]->get_info)(sc->adp, M_VESA_800x600, &info) == 0)) {
340 if (sc->flags & SC_SPLASH_SCRN)
341 splash_term(sc->adp);
343 sc_set_graphics_mode(scp, NULL, M_VESA_800x600);
344 sc_set_pixel_mode(scp, NULL, COL, ROW, 16);
345 sc->initial_mode = M_VESA_800x600;
347 /* put up the splash again! */
348 if (sc->flags & SC_SPLASH_SCRN)
349 splash_init(sc->adp, scsplash_callback, sc);
352 #endif /* SC_PIXEL_MODE */
354 /* initialize cursor */
356 update_cursor_image(scp);
358 /* get screen update going */
361 /* set up the keyboard */
362 kbd_ioctl(sc->kbd, KDSKBMODE, (caddr_t)&scp->kbd_mode);
363 update_kbd_state(scp, scp->status, LOCK_MASK);
365 printf("sc%d: %s <%d virtual consoles, flags=0x%x>\n",
366 unit, adapter_name(sc->adp), sc->vtys, sc->config);
368 printf("sc%d:", unit);
369 if (sc->adapter >= 0)
370 printf(" fb%d", sc->adapter);
371 if (sc->keyboard >= 0)
372 printf(", kbd%d", sc->keyboard);
374 printf(", terminal emulator: %s (%s)",
375 scp->tsw->te_name, scp->tsw->te_desc);
379 /* register a shutdown callback for the kernel console */
380 if (sc_console_unit == unit)
381 EVENTHANDLER_REGISTER(shutdown_pre_sync, scshutdown,
382 (void *)(uintptr_t)unit, SHUTDOWN_PRI_DEFAULT);
384 for (vc = 0; vc < sc->vtys; vc++) {
385 dev = make_dev(&sc_cdevsw, vc + unit * MAXCONS,
386 UID_ROOT, GID_WHEEL, 0600, "ttyv%r", vc + unit * MAXCONS);
389 * The first vty already has struct tty and scr_stat initialized
390 * in scinit(). The other vtys will have these structs when
395 dev = make_dev(&sc_cdevsw, SC_CONSOLECTL,
396 UID_ROOT, GID_WHEEL, 0600, "consolectl");
397 dev->si_tty = sc_console_tty = ttymalloc(sc_console_tty);
398 SC_STAT(dev) = sc_console;
411 * As soon as malloc() becomes functional, we had better allocate
412 * various buffers for the kernel console.
415 if (sc_console_unit < 0) /* sc_console == NULL */
418 /* copy the temporary buffer to the final buffer */
419 sc_alloc_scr_buffer(sc_console, FALSE, FALSE);
421 #ifndef SC_NO_CUTPASTE
422 sc_alloc_cut_buffer(sc_console, FALSE);
425 #ifndef SC_NO_HISTORY
426 /* initialize history buffer & pointers */
427 sc_alloc_history_buffer(sc_console, 0, 0, FALSE);
432 SYSINIT(sc_mem, SI_SUB_KMEM, SI_ORDER_ANY, scmeminit, NULL);
435 scdevtounit(dev_t dev)
437 int vty = SC_VTY(dev);
439 if (vty == SC_CONSOLECTL)
440 return ((sc_console != NULL) ? sc_console->sc->unit : -1);
441 else if ((vty < 0) || (vty >= MAXCONS*sc_max_unit()))
448 scopen(dev_t dev, int flag, int mode, struct thread *td)
450 int unit = scdevtounit(dev);
457 DPRINTF(5, ("scopen: dev:%d,%d, unit:%d, vty:%d\n",
458 major(dev), minor(dev), unit, SC_VTY(dev)));
460 sc = sc_get_softc(unit, (sc_console_unit == unit) ? SC_KERNEL_CONSOLE : 0);
464 tp = dev->si_tty = ttymalloc(dev->si_tty);
465 tp->t_oproc = scstart;
466 tp->t_param = scparam;
467 tp->t_stop = nottystop;
469 if (!ISTTYOPEN(tp)) {
471 /* Use the current setting of the <-- key as default VERASE. */
472 /* If the Delete key is preferable, an stty is necessary */
473 if (sc->kbd != NULL) {
474 key.keynum = KEYCODE_BS;
475 kbd_ioctl(sc->kbd, GIO_KEYMAPENT, (caddr_t)&key);
476 tp->t_cc[VERASE] = key.key.map[0];
478 tp->t_iflag = TTYDEF_IFLAG;
479 tp->t_oflag = TTYDEF_OFLAG;
480 tp->t_cflag = TTYDEF_CFLAG;
481 tp->t_lflag = TTYDEF_LFLAG;
482 tp->t_ispeed = tp->t_ospeed = TTYDEF_SPEED;
483 scparam(tp, &tp->t_termios);
484 (*linesw[tp->t_line].l_modem)(tp, 1);
487 if (tp->t_state & TS_XCLUDE && suser(td))
490 error = (*linesw[tp->t_line].l_open)(dev, tp);
494 scp = SC_STAT(dev) = alloc_scp(sc, SC_VTY(dev));
496 sc_set_pixel_mode(scp, NULL, COL, ROW, 16);
498 if (!tp->t_winsize.ws_col && !tp->t_winsize.ws_row) {
499 tp->t_winsize.ws_col = scp->xsize;
500 tp->t_winsize.ws_row = scp->ysize;
507 scclose(dev_t dev, int flag, int mode, struct thread *td)
509 struct tty *tp = dev->si_tty;
513 if (SC_VTY(dev) != SC_CONSOLECTL) {
514 scp = SC_STAT(tp->t_dev);
515 /* were we in the middle of the VT switching process? */
516 DPRINTF(5, ("sc%d: scclose(), ", scp->sc->unit));
518 if ((scp == scp->sc->cur_scp) && (scp->sc->unit == sc_console_unit))
519 cons_unavail = FALSE;
520 if (finish_vt_rel(scp, TRUE, &s) == 0) /* force release */
521 DPRINTF(5, ("reset WAIT_REL, "));
522 if (finish_vt_acq(scp) == 0) /* force acknowledge */
523 DPRINTF(5, ("reset WAIT_ACQ, "));
525 if (scp == &main_console) {
528 scp->smode.mode = VT_AUTO;
531 sc_vtb_destroy(&scp->vtb);
532 sc_vtb_destroy(&scp->scr);
533 sc_free_history_buffer(scp, scp->ysize);
540 scp->smode.mode = VT_AUTO;
542 scp->kbd_mode = K_XLATE;
543 if (scp == scp->sc->cur_scp)
544 kbd_ioctl(scp->sc->kbd, KDSKBMODE, (caddr_t)&scp->kbd_mode);
545 DPRINTF(5, ("done.\n"));
548 (*linesw[tp->t_line].l_close)(tp, flag);
555 scread(dev_t dev, struct uio *uio, int flag)
557 if (!sc_saver_keyb_only)
558 sc_touch_scrn_saver();
559 return ttyread(dev, uio, flag);
563 sckbdevent(keyboard_t *thiskbd, int event, void *arg)
571 sc = (sc_softc_t *)arg;
572 /* assert(thiskbd == sc->kbd) */
577 case KBDIO_UNLOADING:
580 kbd_release(thiskbd, (void *)&sc->keyboard);
587 * Loop while there is still input to get from the keyboard.
588 * I don't think this is nessesary, and it doesn't fix
589 * the Xaccel-2.1 keyboard hang, but it can't hurt. XXX
591 while ((c = scgetc(sc, SCGETC_NONBLOCK)) != NOKEY) {
593 cur_tty = VIRTUAL_TTY(sc, sc->cur_scp->index);
594 if (!ISTTYOPEN(cur_tty)) {
595 cur_tty = sc_console_tty;
596 if (!ISTTYOPEN(cur_tty))
600 if ((*sc->cur_scp->tsw->te_input)(sc->cur_scp, c, cur_tty))
603 switch (KEYFLAGS(c)) {
604 case 0x0000: /* normal key */
605 (*linesw[cur_tty->t_line].l_rint)(KEYCHAR(c), cur_tty);
607 case FKEY: /* function key, return string */
608 cp = kbd_get_fkeystr(thiskbd, KEYCHAR(c), &len);
611 (*linesw[cur_tty->t_line].l_rint)(*cp++, cur_tty);
614 case MKEY: /* meta is active, prepend ESC */
615 (*linesw[cur_tty->t_line].l_rint)(0x1b, cur_tty);
616 (*linesw[cur_tty->t_line].l_rint)(KEYCHAR(c), cur_tty);
618 case BKEY: /* backtab fixed sequence (esc [ Z) */
619 (*linesw[cur_tty->t_line].l_rint)(0x1b, cur_tty);
620 (*linesw[cur_tty->t_line].l_rint)('[', cur_tty);
621 (*linesw[cur_tty->t_line].l_rint)('Z', cur_tty);
626 sc->cur_scp->status |= MOUSE_HIDDEN;
632 scparam(struct tty *tp, struct termios *t)
634 tp->t_ispeed = t->c_ispeed;
635 tp->t_ospeed = t->c_ospeed;
636 tp->t_cflag = t->c_cflag;
641 scioctl(dev_t dev, u_long cmd, caddr_t data, int flag, struct thread *td)
652 /* If there is a user_ioctl function call that first */
654 error = (*sc_user_ioctl)(dev, cmd, data, flag, td);
655 if (error != ENOIOCTL)
659 error = sc_vid_ioctl(tp, cmd, data, flag, td);
660 if (error != ENOIOCTL)
663 #ifndef SC_NO_HISTORY
664 error = sc_hist_ioctl(tp, cmd, data, flag, td);
665 if (error != ENOIOCTL)
669 #ifndef SC_NO_SYSMOUSE
670 error = sc_mouse_ioctl(tp, cmd, data, flag, td);
671 if (error != ENOIOCTL)
675 scp = SC_STAT(tp->t_dev);
676 /* assert(scp != NULL) */
677 /* scp is sc_console, if SC_VTY(dev) == SC_CONSOLECTL. */
681 error = (*scp->tsw->te_ioctl)(scp, tp, cmd, data, flag, td);
682 if (error != ENOIOCTL)
686 switch (cmd) { /* process console hardware related ioctl's */
688 case GIO_ATTR: /* get current attributes */
689 /* this ioctl is not processed here, but in the terminal emulator */
692 case GIO_COLOR: /* is this a color console ? */
693 *(int *)data = (sc->adp->va_flags & V_ADP_COLOR) ? 1 : 0;
696 case CONS_BLANKTIME: /* set screen saver timeout (0 = no saver) */
697 if (*(int *)data < 0 || *(int *)data > MAX_BLANKTIME)
700 scrn_blank_time = *(int *)data;
701 run_scrn_saver = (scrn_blank_time != 0);
705 case CONS_CURSORTYPE: /* set cursor type (obsolete) */
707 *(int *)data &= CONS_CURSOR_ATTRS;
708 sc_change_cursor_shape(scp, *(int *)data, -1, -1);
712 case CONS_GETCURSORSHAPE: /* get cursor shape (new interface) */
713 if (((int *)data)[0] & CONS_LOCAL_CURSOR) {
714 ((int *)data)[0] = scp->curr_curs_attr.flags;
715 ((int *)data)[1] = scp->curr_curs_attr.base;
716 ((int *)data)[2] = scp->curr_curs_attr.height;
718 ((int *)data)[0] = sc->curs_attr.flags;
719 ((int *)data)[1] = sc->curs_attr.base;
720 ((int *)data)[2] = sc->curs_attr.height;
724 case CONS_SETCURSORSHAPE: /* set cursor shape (new interface) */
726 sc_change_cursor_shape(scp, ((int *)data)[0],
727 ((int *)data)[1], ((int *)data)[2]);
731 case CONS_BELLTYPE: /* set bell type sound/visual */
732 if ((*(int *)data) & 0x01)
733 sc->flags |= SC_VISUAL_BELL;
735 sc->flags &= ~SC_VISUAL_BELL;
736 if ((*(int *)data) & 0x02)
737 sc->flags |= SC_QUIET_BELL;
739 sc->flags &= ~SC_QUIET_BELL;
742 case CONS_GETINFO: /* get current (virtual) console info */
744 vid_info_t *ptr = (vid_info_t*)data;
745 if (ptr->size == sizeof(struct vid_info)) {
746 ptr->m_num = sc->cur_scp->index;
747 ptr->font_size = scp->font_size;
748 ptr->mv_col = scp->xpos;
749 ptr->mv_row = scp->ypos;
750 ptr->mv_csz = scp->xsize;
751 ptr->mv_rsz = scp->ysize;
753 * The following fields are filled by the terminal emulator. XXX
760 ptr->mv_grfc.fore = 0; /* not supported */
761 ptr->mv_grfc.back = 0; /* not supported */
762 ptr->mv_ovscan = scp->border;
763 if (scp == sc->cur_scp)
765 ptr->mk_keylock = scp->status & LOCK_MASK;
771 case CONS_GETVERS: /* get version number */
772 *(int*)data = 0x200; /* version 2.0 */
775 case CONS_IDLE: /* see if the screen has been idle */
777 * When the screen is in the GRAPHICS_MODE or UNKNOWN_MODE,
778 * the user process may have been writing something on the
779 * screen and syscons is not aware of it. Declare the screen
780 * is NOT idle if it is in one of these modes. But there is
781 * an exception to it; if a screen saver is running in the
782 * graphics mode in the current screen, we should say that the
783 * screen has been idle.
785 *(int *)data = (sc->flags & SC_SCRN_IDLE)
786 && (!ISGRAPHSC(sc->cur_scp)
787 || (sc->cur_scp->status & SAVER_RUNNING));
790 case CONS_SAVERMODE: /* set saver mode */
791 switch(*(int *)data) {
794 /* if a LKM screen saver is running, stop it first. */
795 scsplash_stick(FALSE);
796 saver_mode = *(int *)data;
799 if ((error = wait_scrn_saver_stop(NULL))) {
804 run_scrn_saver = TRUE;
805 if (saver_mode == CONS_USR_SAVER)
806 scp->status |= SAVER_RUNNING;
808 scp->status &= ~SAVER_RUNNING;
809 scsplash_stick(TRUE);
814 if ((saver_mode == CONS_USR_SAVER) && (scp->status & SAVER_RUNNING))
815 scp->status &= ~SAVER_RUNNING;
816 saver_mode = *(int *)data;
824 case CONS_SAVERSTART: /* immediately start/stop the screen saver */
826 * Note that this ioctl does not guarantee the screen saver
827 * actually starts or stops. It merely attempts to do so...
830 run_scrn_saver = (*(int *)data != 0);
832 sc->scrn_time_stamp -= scrn_blank_time;
836 case CONS_SCRSHOT: /* get a screen shot */
838 scrshot_t *ptr = (scrshot_t*)data;
840 if (ISGRAPHSC(scp)) {
844 if (scp->xsize != ptr->xsize || scp->ysize != ptr->ysize) {
848 copyout ((void*)scp->vtb.vtb_buffer, ptr->buf,
849 ptr->xsize * ptr->ysize * sizeof(u_int16_t));
854 case VT_SETMODE: /* set screen switcher mode */
856 struct vt_mode *mode;
859 mode = (struct vt_mode *)data;
860 DPRINTF(5, ("sc%d: VT_SETMODE ", sc->unit));
861 if (scp->smode.mode == VT_PROCESS) {
862 p1 = pfind(scp->pid);
863 if (scp->proc == p1 && scp->proc != td->td_proc) {
866 DPRINTF(5, ("error EPERM\n"));
873 if (mode->mode == VT_AUTO) {
874 scp->smode.mode = VT_AUTO;
877 DPRINTF(5, ("VT_AUTO, "));
878 if ((scp == sc->cur_scp) && (sc->unit == sc_console_unit))
879 cons_unavail = FALSE;
880 /* were we in the middle of the vty switching process? */
881 if (finish_vt_rel(scp, TRUE, &s) == 0)
882 DPRINTF(5, ("reset WAIT_REL, "));
883 if (finish_vt_acq(scp) == 0)
884 DPRINTF(5, ("reset WAIT_ACQ, "));
886 if (!ISSIGVALID(mode->relsig) || !ISSIGVALID(mode->acqsig)
887 || !ISSIGVALID(mode->frsig)) {
889 DPRINTF(5, ("error EINVAL\n"));
892 DPRINTF(5, ("VT_PROCESS %d, ", td->td_proc->p_pid));
893 bcopy(data, &scp->smode, sizeof(struct vt_mode));
894 scp->proc = td->td_proc;
895 scp->pid = scp->proc->p_pid;
896 if ((scp == sc->cur_scp) && (sc->unit == sc_console_unit))
904 case VT_GETMODE: /* get screen switcher mode */
905 bcopy(&scp->smode, data, sizeof(struct vt_mode));
908 case VT_RELDISP: /* screen switcher ioctl */
911 * This must be the current vty which is in the VT_PROCESS
914 if ((scp != sc->cur_scp) || (scp->smode.mode != VT_PROCESS)) {
918 /* ...and this process is controlling it. */
919 if (scp->proc != td->td_proc) {
924 switch(*(int *)data) {
925 case VT_FALSE: /* user refuses to release screen, abort */
926 if ((error = finish_vt_rel(scp, FALSE, &s)) == 0)
927 DPRINTF(5, ("sc%d: VT_FALSE\n", sc->unit));
929 case VT_TRUE: /* user has released screen, go on */
930 if ((error = finish_vt_rel(scp, TRUE, &s)) == 0)
931 DPRINTF(5, ("sc%d: VT_TRUE\n", sc->unit));
933 case VT_ACKACQ: /* acquire acknowledged, switch completed */
934 if ((error = finish_vt_acq(scp)) == 0)
935 DPRINTF(5, ("sc%d: VT_ACKACQ\n", sc->unit));
943 case VT_OPENQRY: /* return free virtual console */
944 for (i = sc->first_vty; i < sc->first_vty + sc->vtys; i++) {
945 tp = VIRTUAL_TTY(sc, i);
946 if (!ISTTYOPEN(tp)) {
947 *(int *)data = i + 1;
953 case VT_ACTIVATE: /* switch to screen *data */
954 i = (*(int *)data == 0) ? scp->index : (*(int *)data - 1);
956 sc_clean_up(sc->cur_scp);
958 return sc_switch_scr(sc, i);
960 case VT_WAITACTIVE: /* wait for switch to occur */
961 i = (*(int *)data == 0) ? scp->index : (*(int *)data - 1);
962 if ((i < sc->first_vty) || (i >= sc->first_vty + sc->vtys))
965 error = sc_clean_up(sc->cur_scp);
969 scp = SC_STAT(SC_DEV(sc, i));
970 if (scp == scp->sc->cur_scp)
972 while ((error=tsleep((caddr_t)&scp->smode, PZERO|PCATCH,
973 "waitvt", 0)) == ERESTART) ;
976 case VT_GETACTIVE: /* get active vty # */
977 *(int *)data = sc->cur_scp->index + 1;
980 case VT_GETINDEX: /* get this vty # */
981 *(int *)data = scp->index + 1;
984 case KDENABIO: /* allow io operations */
988 error = securelevel_gt(td->td_ucred, 0);
992 td->td_frame->tf_eflags |= PSL_IOPL;
996 case KDDISABIO: /* disallow io operations (default) */
998 td->td_frame->tf_eflags &= ~PSL_IOPL;
1002 case KDSKBSTATE: /* set keyboard state (locks) */
1003 if (*(int *)data & ~LOCK_MASK)
1005 scp->status &= ~LOCK_MASK;
1006 scp->status |= *(int *)data;
1007 if (scp == sc->cur_scp)
1008 update_kbd_state(scp, scp->status, LOCK_MASK);
1011 case KDGKBSTATE: /* get keyboard state (locks) */
1012 if (scp == sc->cur_scp)
1013 save_kbd_state(scp);
1014 *(int *)data = scp->status & LOCK_MASK;
1017 case KDGETREPEAT: /* get keyboard repeat & delay rates */
1018 case KDSETREPEAT: /* set keyboard repeat & delay rates (new) */
1019 error = kbd_ioctl(sc->kbd, cmd, data);
1020 if (error == ENOIOCTL)
1024 case KDSETRAD: /* set keyboard repeat & delay rates (old) */
1025 if (*(int *)data & ~0x7f)
1027 error = kbd_ioctl(sc->kbd, cmd, data);
1028 if (error == ENOIOCTL)
1032 case KDSKBMODE: /* set keyboard mode */
1033 switch (*(int *)data) {
1034 case K_XLATE: /* switch to XLT ascii mode */
1035 case K_RAW: /* switch to RAW scancode mode */
1036 case K_CODE: /* switch to CODE mode */
1037 scp->kbd_mode = *(int *)data;
1038 if (scp == sc->cur_scp)
1039 kbd_ioctl(sc->kbd, cmd, data);
1046 case KDGKBMODE: /* get keyboard mode */
1047 *(int *)data = scp->kbd_mode;
1051 error = kbd_ioctl(sc->kbd, cmd, data);
1052 if (error == ENOIOCTL)
1056 case KDMKTONE: /* sound the bell */
1058 sc_bell(scp, (*(int*)data)&0xffff,
1059 (((*(int*)data)>>16)&0xffff)*hz/1000);
1061 sc_bell(scp, scp->bell_pitch, scp->bell_duration);
1064 case KIOCSOUND: /* make tone (*data) hz */
1065 if (scp == sc->cur_scp) {
1067 return sc_tone(*(int *)data);
1073 case KDGKBTYPE: /* get keyboard type */
1074 error = kbd_ioctl(sc->kbd, cmd, data);
1075 if (error == ENOIOCTL) {
1076 /* always return something? XXX */
1081 case KDSETLED: /* set keyboard LED status */
1082 if (*(int *)data & ~LED_MASK) /* FIXME: LOCK_MASK? */
1084 scp->status &= ~LED_MASK;
1085 scp->status |= *(int *)data;
1086 if (scp == sc->cur_scp)
1087 update_kbd_leds(scp, scp->status);
1090 case KDGETLED: /* get keyboard LED status */
1091 if (scp == sc->cur_scp)
1092 save_kbd_state(scp);
1093 *(int *)data = scp->status & LED_MASK;
1096 case CONS_SETKBD: /* set the new keyboard */
1101 newkbd = kbd_get_keyboard(*(int *)data);
1102 if (newkbd == NULL) {
1107 if (sc->kbd != newkbd) {
1108 i = kbd_allocate(newkbd->kb_name, newkbd->kb_unit,
1109 (void *)&sc->keyboard, sckbdevent, sc);
1110 /* i == newkbd->kb_index */
1112 if (sc->kbd != NULL) {
1113 save_kbd_state(sc->cur_scp);
1114 kbd_release(sc->kbd, (void *)&sc->keyboard);
1116 sc->kbd = kbd_get_keyboard(i); /* sc->kbd == newkbd */
1118 kbd_ioctl(sc->kbd, KDSKBMODE,
1119 (caddr_t)&sc->cur_scp->kbd_mode);
1120 update_kbd_state(sc->cur_scp, sc->cur_scp->status,
1123 error = EPERM; /* XXX */
1130 case CONS_RELKBD: /* release the current keyboard */
1133 if (sc->kbd != NULL) {
1134 save_kbd_state(sc->cur_scp);
1135 error = kbd_release(sc->kbd, (void *)&sc->keyboard);
1144 case CONS_GETTERM: /* get the current terminal emulator info */
1148 if (((term_info_t *)data)->ti_index == 0) {
1151 sw = sc_term_match_by_number(((term_info_t *)data)->ti_index);
1154 strncpy(((term_info_t *)data)->ti_name, sw->te_name,
1155 sizeof(((term_info_t *)data)->ti_name));
1156 strncpy(((term_info_t *)data)->ti_desc, sw->te_desc,
1157 sizeof(((term_info_t *)data)->ti_desc));
1158 ((term_info_t *)data)->ti_flags = 0;
1161 ((term_info_t *)data)->ti_name[0] = '\0';
1162 ((term_info_t *)data)->ti_desc[0] = '\0';
1163 ((term_info_t *)data)->ti_flags = 0;
1168 case CONS_SETTERM: /* set the current terminal emulator */
1170 error = sc_init_emulator(scp, ((term_info_t *)data)->ti_name);
1171 /* FIXME: what if scp == sc_console! XXX */
1175 case GIO_SCRNMAP: /* get output translation table */
1176 bcopy(&sc->scr_map, data, sizeof(sc->scr_map));
1179 case PIO_SCRNMAP: /* set output translation table */
1180 bcopy(data, &sc->scr_map, sizeof(sc->scr_map));
1181 for (i=0; i<sizeof(sc->scr_map); i++) {
1182 sc->scr_rmap[sc->scr_map[i]] = i;
1186 case GIO_KEYMAP: /* get keyboard translation table */
1187 case PIO_KEYMAP: /* set keyboard translation table */
1188 case GIO_DEADKEYMAP: /* get accent key translation table */
1189 case PIO_DEADKEYMAP: /* set accent key translation table */
1190 case GETFKEY: /* get function key string */
1191 case SETFKEY: /* set function key string */
1192 error = kbd_ioctl(sc->kbd, cmd, data);
1193 if (error == ENOIOCTL)
1197 #ifndef SC_NO_FONT_LOADING
1199 case PIO_FONT8x8: /* set 8x8 dot font */
1200 if (!ISFONTAVAIL(sc->adp->va_flags))
1202 bcopy(data, sc->font_8, 8*256);
1203 sc->fonts_loaded |= FONT_8;
1206 * Always use the font page #0. XXX
1207 * Don't load if the current font size is not 8x8.
1209 if (ISTEXTSC(sc->cur_scp) && (sc->cur_scp->font_size < 14))
1210 sc_load_font(sc->cur_scp, 0, 8, sc->font_8, 0, 256);
1213 case GIO_FONT8x8: /* get 8x8 dot font */
1214 if (!ISFONTAVAIL(sc->adp->va_flags))
1216 if (sc->fonts_loaded & FONT_8) {
1217 bcopy(sc->font_8, data, 8*256);
1223 case PIO_FONT8x14: /* set 8x14 dot font */
1224 if (!ISFONTAVAIL(sc->adp->va_flags))
1226 bcopy(data, sc->font_14, 14*256);
1227 sc->fonts_loaded |= FONT_14;
1230 * Always use the font page #0. XXX
1231 * Don't load if the current font size is not 8x14.
1233 if (ISTEXTSC(sc->cur_scp)
1234 && (sc->cur_scp->font_size >= 14)
1235 && (sc->cur_scp->font_size < 16))
1236 sc_load_font(sc->cur_scp, 0, 14, sc->font_14, 0, 256);
1239 case GIO_FONT8x14: /* get 8x14 dot font */
1240 if (!ISFONTAVAIL(sc->adp->va_flags))
1242 if (sc->fonts_loaded & FONT_14) {
1243 bcopy(sc->font_14, data, 14*256);
1249 case PIO_FONT8x16: /* set 8x16 dot font */
1250 if (!ISFONTAVAIL(sc->adp->va_flags))
1252 bcopy(data, sc->font_16, 16*256);
1253 sc->fonts_loaded |= FONT_16;
1256 * Always use the font page #0. XXX
1257 * Don't load if the current font size is not 8x16.
1259 if (ISTEXTSC(sc->cur_scp) && (sc->cur_scp->font_size >= 16))
1260 sc_load_font(sc->cur_scp, 0, 16, sc->font_16, 0, 256);
1263 case GIO_FONT8x16: /* get 8x16 dot font */
1264 if (!ISFONTAVAIL(sc->adp->va_flags))
1266 if (sc->fonts_loaded & FONT_16) {
1267 bcopy(sc->font_16, data, 16*256);
1273 #endif /* SC_NO_FONT_LOADING */
1279 error = (*linesw[tp->t_line].l_ioctl)(tp, cmd, data, flag, td);
1280 if (error != ENOIOCTL)
1282 error = ttioctl(tp, cmd, data, flag);
1283 if (error != ENOIOCTL)
1289 scstart(struct tty *tp)
1293 u_char buf[PCBURST];
1294 scr_stat *scp = SC_STAT(tp->t_dev);
1296 if (scp->status & SLKED || scp->sc->blink_in_progress)
1299 if (!(tp->t_state & (TS_TIMEOUT | TS_BUSY | TS_TTSTOP))) {
1300 tp->t_state |= TS_BUSY;
1303 len = q_to_b(rbp, buf, PCBURST);
1305 sc_puts(scp, buf, len);
1308 tp->t_state &= ~TS_BUSY;
1315 sccnprobe(struct consdev *cp)
1317 #if __i386__ || __ia64__
1321 cp->cn_pri = sc_get_cons_priority(&unit, &flags);
1323 /* a video card is always required */
1324 if (!scvidprobe(unit, flags, TRUE))
1325 cp->cn_pri = CN_DEAD;
1327 /* syscons will become console even when there is no keyboard */
1328 sckbdprobe(unit, flags, TRUE);
1330 if (cp->cn_pri == CN_DEAD)
1333 /* initialize required fields */
1334 cp->cn_dev = makedev(CDEV_MAJOR, SC_CONSOLECTL);
1335 #endif /* __i386__ || __ia64__ */
1339 * alpha use sccnattach() rather than cnprobe()/cninit()/cnterm()
1340 * interface to install the console. Always return CN_DEAD from
1343 cp->cn_pri = CN_DEAD;
1344 #endif /* __alpha__ */
1348 sccninit(struct consdev *cp)
1350 #if __i386__ || __ia64__
1354 sc_get_cons_priority(&unit, &flags);
1355 scinit(unit, flags | SC_KERNEL_CONSOLE);
1356 sc_console_unit = unit;
1357 sc_console = SC_STAT(sc_get_softc(unit, SC_KERNEL_CONSOLE)->dev[0]);
1358 #endif /* __i386__ */
1361 /* SHOULDN'T REACH HERE */
1362 #endif /* __alpha__ */
1366 sccnterm(struct consdev *cp)
1368 /* we are not the kernel console any more, release everything */
1370 if (sc_console_unit < 0)
1371 return; /* shouldn't happen */
1373 #if __i386__ || __ia64__
1375 sc_clear_screen(sc_console);
1376 sccnupdate(sc_console);
1378 scterm(sc_console_unit, SC_KERNEL_CONSOLE);
1379 sc_console_unit = -1;
1381 #endif /* __i386__ */
1384 /* do nothing XXX */
1385 #endif /* __alpha__ */
1393 static struct consdev consdev;
1397 bcopy(&sc_consdev, &consdev, sizeof(sc_consdev));
1398 consdev.cn_pri = sc_get_cons_priority(&unit, &flags);
1400 /* a video card is always required */
1401 if (!scvidprobe(unit, flags, TRUE))
1402 consdev.cn_pri = CN_DEAD;
1404 /* alpha doesn't allow the console being without a keyboard... Why? */
1405 if (!sckbdprobe(unit, flags, TRUE))
1406 consdev.cn_pri = CN_DEAD;
1408 if (consdev.cn_pri == CN_DEAD)
1411 scinit(unit, flags | SC_KERNEL_CONSOLE);
1412 sc_console_unit = unit;
1413 sc_console = SC_STAT(sc_get_softc(unit, SC_KERNEL_CONSOLE)->dev[0]);
1414 consdev.cn_dev = makedev(CDEV_MAJOR, 0);
1418 #endif /* __alpha__ */
1421 sccnputc(dev_t dev, int c)
1424 scr_stat *scp = sc_console;
1426 #ifndef SC_NO_HISTORY
1428 #endif /* !SC_NO_HISTORY */
1431 /* assert(sc_console != NULL) */
1433 #ifndef SC_NO_HISTORY
1434 if (scp == scp->sc->cur_scp && scp->status & SLKED) {
1435 scp->status &= ~SLKED;
1436 update_kbd_state(scp, scp->status, SLKED);
1437 if (scp->status & BUFFER_SAVED) {
1438 if (!sc_hist_restore(scp))
1439 sc_remove_cutmarking(scp);
1440 scp->status &= ~BUFFER_SAVED;
1441 scp->status |= CURSOR_ENABLED;
1442 sc_draw_cursor_image(scp);
1444 tp = VIRTUAL_TTY(scp->sc, scp->index);
1448 #endif /* !SC_NO_HISTORY */
1451 if (kernel_console_ts != NULL)
1452 scp->ts = kernel_console_ts;
1454 sc_puts(scp, buf, 1);
1457 s = spltty(); /* block sckbdevent and scrn_timer */
1465 return sccngetch(0);
1469 sccncheckc(dev_t dev)
1471 return sccngetch(SCGETC_NONBLOCK);
1475 sccndbctl(dev_t dev, int on)
1477 /* assert(sc_console_unit >= 0) */
1478 /* try to switch to the kernel console screen */
1479 if (on && debugger == 0) {
1481 * TRY to make sure the screen saver is stopped,
1482 * and the screen is updated before switching to
1487 && sc_console->sc->cur_scp->smode.mode == VT_AUTO
1488 && sc_console->smode.mode == VT_AUTO) {
1489 sc_console->sc->cur_scp->status |= MOUSE_HIDDEN;
1490 ++debugger; /* XXX */
1491 sc_switch_scr(sc_console->sc, sc_console->index);
1492 --debugger; /* XXX */
1502 sccngetch(int flags)
1504 static struct fkeytab fkey;
1509 int s = spltty(); /* block sckbdevent and scrn_timer while we poll */
1512 /* assert(sc_console != NULL) */
1515 * Stop the screen saver and update the screen if necessary.
1516 * What if we have been running in the screen saver code... XXX
1518 sc_touch_scrn_saver();
1519 scp = sc_console->sc->cur_scp; /* XXX */
1522 if (fkeycp < fkey.len) {
1524 return fkey.str[fkeycp++];
1527 if (scp->sc->kbd == NULL) {
1533 * Make sure the keyboard is accessible even when the kbd device
1534 * driver is disabled.
1536 kbd_enable(scp->sc->kbd);
1538 /* we shall always use the keyboard in the XLATE mode here */
1539 cur_mode = scp->kbd_mode;
1540 scp->kbd_mode = K_XLATE;
1541 kbd_ioctl(scp->sc->kbd, KDSKBMODE, (caddr_t)&scp->kbd_mode);
1543 kbd_poll(scp->sc->kbd, TRUE);
1544 c = scgetc(scp->sc, SCGETC_CN | flags);
1545 kbd_poll(scp->sc->kbd, FALSE);
1547 scp->kbd_mode = cur_mode;
1548 kbd_ioctl(scp->sc->kbd, KDSKBMODE, (caddr_t)&scp->kbd_mode);
1549 kbd_disable(scp->sc->kbd);
1552 switch (KEYFLAGS(c)) {
1553 case 0: /* normal char */
1555 case FKEY: /* function key */
1556 p = kbd_get_fkeystr(scp->sc->kbd, KEYCHAR(c), (size_t *)&fkeycp);
1558 if ((p != NULL) && (fkey.len > 0)) {
1559 bcopy(p, fkey.str, fkey.len);
1573 sccnupdate(scr_stat *scp)
1575 /* this is a cut-down version of scrn_timer()... */
1577 if (scp->sc->font_loading_in_progress || scp->sc->videoio_in_progress)
1580 if (debugger > 0 || panicstr || shutdown_in_progress) {
1581 sc_touch_scrn_saver();
1582 } else if (scp != scp->sc->cur_scp) {
1586 if (!run_scrn_saver)
1587 scp->sc->flags &= ~SC_SCRN_IDLE;
1589 if ((saver_mode != CONS_LKM_SAVER) || !(scp->sc->flags & SC_SCRN_IDLE))
1590 if (scp->sc->flags & SC_SCRN_BLANKED)
1591 stop_scrn_saver(scp->sc, current_saver);
1594 if (scp != scp->sc->cur_scp || scp->sc->blink_in_progress
1595 || scp->sc->switch_in_progress)
1598 * FIXME: unlike scrn_timer(), we call scrn_update() from here even
1599 * when write_in_progress is non-zero. XXX
1602 if (!ISGRAPHSC(scp) && !(scp->sc->flags & SC_SCRN_BLANKED))
1603 scrn_update(scp, TRUE);
1607 scrn_timer(void *arg)
1609 static int kbd_interval = 0;
1616 again = (arg != NULL);
1618 sc = (sc_softc_t *)arg;
1619 else if (sc_console != NULL)
1620 sc = sc_console->sc;
1624 /* don't do anything when we are performing some I/O operations */
1625 if (sc->font_loading_in_progress || sc->videoio_in_progress) {
1627 timeout(scrn_timer, sc, hz / 10);
1632 if ((sc->kbd == NULL) && (sc->config & SC_AUTODETECT_KBD)) {
1633 /* try to allocate a keyboard automatically */
1634 if (++kbd_interval >= 25) {
1635 sc->keyboard = kbd_allocate("*", -1, (void *)&sc->keyboard,
1637 if (sc->keyboard >= 0) {
1638 sc->kbd = kbd_get_keyboard(sc->keyboard);
1639 kbd_ioctl(sc->kbd, KDSKBMODE,
1640 (caddr_t)&sc->cur_scp->kbd_mode);
1641 update_kbd_state(sc->cur_scp, sc->cur_scp->status,
1648 /* find the vty to update */
1651 /* should we stop the screen saver? */
1652 getmicrouptime(&tv);
1653 if (debugger > 0 || panicstr || shutdown_in_progress)
1654 sc_touch_scrn_saver();
1655 if (run_scrn_saver) {
1656 if (tv.tv_sec > sc->scrn_time_stamp + scrn_blank_time)
1657 sc->flags |= SC_SCRN_IDLE;
1659 sc->flags &= ~SC_SCRN_IDLE;
1661 sc->scrn_time_stamp = tv.tv_sec;
1662 sc->flags &= ~SC_SCRN_IDLE;
1663 if (scrn_blank_time > 0)
1664 run_scrn_saver = TRUE;
1667 if ((saver_mode != CONS_LKM_SAVER) || !(sc->flags & SC_SCRN_IDLE))
1668 if (sc->flags & SC_SCRN_BLANKED)
1669 stop_scrn_saver(sc, current_saver);
1672 /* should we just return ? */
1673 if (sc->blink_in_progress || sc->switch_in_progress
1674 || sc->write_in_progress) {
1676 timeout(scrn_timer, sc, hz / 10);
1681 /* Update the screen */
1682 scp = sc->cur_scp; /* cur_scp may have changed... */
1683 if (!ISGRAPHSC(scp) && !(sc->flags & SC_SCRN_BLANKED))
1684 scrn_update(scp, TRUE);
1687 /* should we activate the screen saver? */
1688 if ((saver_mode == CONS_LKM_SAVER) && (sc->flags & SC_SCRN_IDLE))
1689 if (!ISGRAPHSC(scp) || (sc->flags & SC_SCRN_BLANKED))
1690 (*current_saver)(sc, TRUE);
1694 timeout(scrn_timer, sc, hz / 25);
1699 and_region(int *s1, int *e1, int s2, int e2)
1701 if (*e1 < s2 || e2 < *s1)
1703 *s1 = imax(*s1, s2);
1704 *e1 = imin(*e1, e2);
1709 scrn_update(scr_stat *scp, int show_cursor)
1716 /* assert(scp == scp->sc->cur_scp) */
1718 ++scp->sc->videoio_in_progress;
1720 #ifndef SC_NO_CUTPASTE
1721 /* remove the previous mouse pointer image if necessary */
1722 if (scp->status & MOUSE_VISIBLE) {
1724 e = scp->mouse_pos + scp->xsize + 1;
1725 if ((scp->status & (MOUSE_MOVED | MOUSE_HIDDEN))
1726 || and_region(&s, &e, scp->start, scp->end)
1727 || ((scp->status & CURSOR_ENABLED) &&
1728 (scp->cursor_pos != scp->cursor_oldpos) &&
1729 (and_region(&s, &e, scp->cursor_pos, scp->cursor_pos)
1730 || and_region(&s, &e, scp->cursor_oldpos, scp->cursor_oldpos)))) {
1731 sc_remove_mouse_image(scp);
1732 if (scp->end >= scp->xsize*scp->ysize)
1733 scp->end = scp->xsize*scp->ysize - 1;
1736 #endif /* !SC_NO_CUTPASTE */
1740 if (scp->end >= scp->xsize*scp->ysize) {
1741 printf("scrn_update(): scp->end %d > size_of_screen!!\n", scp->end);
1742 scp->end = scp->xsize*scp->ysize - 1;
1744 if (scp->start < 0) {
1745 printf("scrn_update(): scp->start %d < 0\n", scp->start);
1750 /* update screen image */
1751 if (scp->start <= scp->end) {
1752 if (scp->mouse_cut_end >= 0) {
1753 /* there is a marked region for cut & paste */
1754 if (scp->mouse_cut_start <= scp->mouse_cut_end) {
1755 start = scp->mouse_cut_start;
1756 end = scp->mouse_cut_end;
1758 start = scp->mouse_cut_end;
1759 end = scp->mouse_cut_start - 1;
1763 /* does the cut-mark region overlap with the update region? */
1764 if (and_region(&s, &e, scp->start, scp->end)) {
1765 (*scp->rndr->draw)(scp, s, e - s + 1, TRUE);
1768 if (and_region(&s, &e, scp->start, scp->end))
1769 (*scp->rndr->draw)(scp, s, e - s + 1, FALSE);
1771 e = scp->xsize*scp->ysize - 1;
1772 if (and_region(&s, &e, scp->start, scp->end))
1773 (*scp->rndr->draw)(scp, s, e - s + 1, FALSE);
1775 (*scp->rndr->draw)(scp, scp->start,
1776 scp->end - scp->start + 1, FALSE);
1779 (*scp->rndr->draw)(scp, scp->start,
1780 scp->end - scp->start + 1, FALSE);
1784 /* we are not to show the cursor and the mouse pointer... */
1787 scp->start = scp->xsize*scp->ysize - 1;
1788 --scp->sc->videoio_in_progress;
1792 /* update cursor image */
1793 if (scp->status & CURSOR_ENABLED) {
1796 /* did cursor move since last time ? */
1797 if (scp->cursor_pos != scp->cursor_oldpos) {
1798 /* do we need to remove old cursor image ? */
1799 if (!and_region(&s, &e, scp->cursor_oldpos, scp->cursor_oldpos))
1800 sc_remove_cursor_image(scp);
1801 sc_draw_cursor_image(scp);
1803 if (and_region(&s, &e, scp->cursor_pos, scp->cursor_pos))
1804 /* cursor didn't move, but has been overwritten */
1805 sc_draw_cursor_image(scp);
1806 else if (scp->curs_attr.flags & CONS_BLINK_CURSOR)
1807 /* if it's a blinking cursor, update it */
1808 (*scp->rndr->blink_cursor)(scp, scp->cursor_pos,
1809 sc_inside_cutmark(scp,
1814 #ifndef SC_NO_CUTPASTE
1815 /* update "pseudo" mouse pointer image */
1816 if (scp->sc->flags & SC_MOUSE_ENABLED) {
1817 if (!(scp->status & (MOUSE_VISIBLE | MOUSE_HIDDEN))) {
1818 scp->status &= ~MOUSE_MOVED;
1819 sc_draw_mouse_image(scp);
1822 #endif /* SC_NO_CUTPASTE */
1825 scp->start = scp->xsize*scp->ysize - 1;
1827 --scp->sc->videoio_in_progress;
1832 scsplash_callback(int event, void *arg)
1837 sc = (sc_softc_t *)arg;
1841 if (add_scrn_saver(scsplash_saver) == 0) {
1842 sc->flags &= ~SC_SAVER_FAILED;
1843 run_scrn_saver = TRUE;
1844 if (cold && !(boothowto & (RB_VERBOSE | RB_CONFIG))) {
1845 scsplash_stick(TRUE);
1846 (*current_saver)(sc, TRUE);
1852 if (current_saver == scsplash_saver) {
1853 scsplash_stick(FALSE);
1854 error = remove_scrn_saver(scsplash_saver);
1866 scsplash_saver(sc_softc_t *sc, int show)
1868 static int busy = FALSE;
1877 if (!(sc->flags & SC_SAVER_FAILED)) {
1878 if (!(sc->flags & SC_SCRN_BLANKED))
1879 set_scrn_saver_mode(scp, -1, NULL, 0);
1880 switch (splash(sc->adp, TRUE)) {
1881 case 0: /* succeeded */
1883 case EAGAIN: /* try later */
1884 restore_scrn_saver_mode(scp, FALSE);
1885 sc_touch_scrn_saver(); /* XXX */
1888 sc->flags |= SC_SAVER_FAILED;
1889 scsplash_stick(FALSE);
1890 restore_scrn_saver_mode(scp, TRUE);
1891 printf("scsplash_saver(): failed to put up the image\n");
1895 } else if (!sticky_splash) {
1896 if ((sc->flags & SC_SCRN_BLANKED) && (splash(sc->adp, FALSE) == 0))
1897 restore_scrn_saver_mode(scp, TRUE);
1903 add_scrn_saver(void (*this_saver)(sc_softc_t *, int))
1908 if (current_saver != none_saver) {
1909 error = remove_scrn_saver(current_saver);
1914 if (current_saver != none_saver)
1917 run_scrn_saver = FALSE;
1918 saver_mode = CONS_LKM_SAVER;
1919 current_saver = this_saver;
1924 remove_scrn_saver(void (*this_saver)(sc_softc_t *, int))
1926 if (current_saver != this_saver)
1931 * In order to prevent `current_saver' from being called by
1932 * the timeout routine `scrn_timer()' while we manipulate
1933 * the saver list, we shall set `current_saver' to `none_saver'
1934 * before stopping the current saver, rather than blocking by `splXX()'.
1936 current_saver = none_saver;
1938 stop_scrn_saver(this_saver);
1941 /* unblank all blanked screens */
1942 wait_scrn_saver_stop(NULL);
1946 current_saver = none_saver;
1951 set_scrn_saver_mode(scr_stat *scp, int mode, u_char *pal, int border)
1955 /* assert(scp == scp->sc->cur_scp) */
1957 if (!ISGRAPHSC(scp))
1958 sc_remove_cursor_image(scp);
1959 scp->splash_save_mode = scp->mode;
1960 scp->splash_save_status = scp->status & (GRAPHICS_MODE | PIXEL_MODE);
1961 scp->status &= ~(GRAPHICS_MODE | PIXEL_MODE);
1962 scp->status |= (UNKNOWN_MODE | SAVER_RUNNING);
1963 scp->sc->flags |= SC_SCRN_BLANKED;
1969 if (set_mode(scp) == 0) {
1970 if (scp->sc->adp->va_info.vi_flags & V_INFO_GRAPHICS)
1971 scp->status |= GRAPHICS_MODE;
1972 #ifndef SC_NO_PALETTE_LOADING
1974 load_palette(scp->sc->adp, pal);
1976 sc_set_border(scp, border);
1980 scp->mode = scp->splash_save_mode;
1981 scp->status &= ~(UNKNOWN_MODE | SAVER_RUNNING);
1982 scp->status |= scp->splash_save_status;
1989 restore_scrn_saver_mode(scr_stat *scp, int changemode)
1995 /* assert(scp == scp->sc->cur_scp) */
1998 status = scp->status;
1999 scp->mode = scp->splash_save_mode;
2000 scp->status &= ~(UNKNOWN_MODE | SAVER_RUNNING);
2001 scp->status |= scp->splash_save_status;
2002 scp->sc->flags &= ~SC_SCRN_BLANKED;
2004 if (!ISGRAPHSC(scp))
2005 sc_draw_cursor_image(scp);
2010 if (set_mode(scp) == 0) {
2011 #ifndef SC_NO_PALETTE_LOADING
2012 load_palette(scp->sc->adp, scp->sc->palette);
2019 scp->status = status;
2026 stop_scrn_saver(sc_softc_t *sc, void (*saver)(sc_softc_t *, int))
2028 (*saver)(sc, FALSE);
2029 run_scrn_saver = FALSE;
2030 /* the screen saver may have chosen not to stop after all... */
2031 if (sc->flags & SC_SCRN_BLANKED)
2034 mark_all(sc->cur_scp);
2035 if (sc->delayed_next_scr)
2036 sc_switch_scr(sc, sc->delayed_next_scr - 1);
2038 wakeup((caddr_t)&scrn_blanked);
2042 wait_scrn_saver_stop(sc_softc_t *sc)
2046 while (scrn_blanked > 0) {
2047 run_scrn_saver = FALSE;
2048 if (sc && !(sc->flags & SC_SCRN_BLANKED)) {
2052 error = tsleep((caddr_t)&scrn_blanked, PZERO | PCATCH, "scrsav", 0);
2053 if ((error != 0) && (error != ERESTART))
2056 run_scrn_saver = FALSE;
2059 #endif /* DEV_SPLASH */
2062 sc_touch_scrn_saver(void)
2064 scsplash_stick(FALSE);
2065 run_scrn_saver = FALSE;
2069 sc_switch_scr(sc_softc_t *sc, u_int next_scr)
2076 DPRINTF(5, ("sc0: sc_switch_scr() %d ", next_scr + 1));
2078 /* delay switch if the screen is blanked or being updated */
2079 if ((sc->flags & SC_SCRN_BLANKED) || sc->write_in_progress
2080 || sc->blink_in_progress || sc->videoio_in_progress) {
2081 sc->delayed_next_scr = next_scr + 1;
2082 sc_touch_scrn_saver();
2083 DPRINTF(5, ("switch delayed\n"));
2088 cur_scp = sc->cur_scp;
2090 /* we are in the middle of the vty switching process... */
2091 if (sc->switch_in_progress
2092 && (cur_scp->smode.mode == VT_PROCESS)
2094 p = pfind(cur_scp->pid);
2095 if (cur_scp->proc != p) {
2099 * The controlling process has died!!. Do some clean up.
2100 * NOTE:`cur_scp->proc' and `cur_scp->smode.mode'
2101 * are not reset here yet; they will be cleared later.
2103 DPRINTF(5, ("cur_scp controlling process %d died, ",
2105 if (cur_scp->status & SWITCH_WAIT_REL) {
2107 * Force the previous switch to finish, but return now
2110 DPRINTF(5, ("reset WAIT_REL, "));
2111 finish_vt_rel(cur_scp, TRUE, &s);
2113 DPRINTF(5, ("finishing previous switch\n"));
2115 } else if (cur_scp->status & SWITCH_WAIT_ACQ) {
2116 /* let's assume screen switch has been completed. */
2117 DPRINTF(5, ("reset WAIT_ACQ, "));
2118 finish_vt_acq(cur_scp);
2121 * We are in between screen release and acquisition, and
2122 * reached here via scgetc() or scrn_timer() which has
2123 * interrupted exchange_scr(). Don't do anything stupid.
2125 DPRINTF(5, ("waiting nothing, "));
2131 * The controlling process is alive, but not responding...
2132 * It is either buggy or it may be just taking time.
2133 * The following code is a gross kludge to cope with this
2134 * problem for which there is no clean solution. XXX
2136 if (cur_scp->status & SWITCH_WAIT_REL) {
2137 switch (sc->switch_in_progress++) {
2141 DPRINTF(5, ("sending relsig again, "));
2142 signal_vt_rel(cur_scp);
2149 * Act as if the controlling program returned
2152 DPRINTF(5, ("force reset WAIT_REL, "));
2153 finish_vt_rel(cur_scp, FALSE, &s);
2155 DPRINTF(5, ("act as if VT_FALSE was seen\n"));
2158 } else if (cur_scp->status & SWITCH_WAIT_ACQ) {
2159 switch (sc->switch_in_progress++) {
2163 DPRINTF(5, ("sending acqsig again, "));
2164 signal_vt_acq(cur_scp);
2170 /* clear the flag and finish the previous switch */
2171 DPRINTF(5, ("force reset WAIT_ACQ, "));
2172 finish_vt_acq(cur_scp);
2180 * Return error if an invalid argument is given, or vty switch
2181 * is still in progress.
2183 if ((next_scr < sc->first_vty) || (next_scr >= sc->first_vty + sc->vtys)
2184 || sc->switch_in_progress) {
2186 sc_bell(cur_scp, bios_value.bell_pitch, BELL_DURATION);
2187 DPRINTF(5, ("error 1\n"));
2192 * Don't allow switching away from the graphics mode vty
2193 * if the switch mode is VT_AUTO, unless the next vty is the same
2194 * as the current or the current vty has been closed (but showing).
2196 tp = VIRTUAL_TTY(sc, cur_scp->index);
2197 if ((cur_scp->index != next_scr)
2199 && (cur_scp->smode.mode == VT_AUTO)
2200 && ISGRAPHSC(cur_scp)) {
2202 sc_bell(cur_scp, bios_value.bell_pitch, BELL_DURATION);
2203 DPRINTF(5, ("error, graphics mode\n"));
2208 * Is the wanted vty open? Don't allow switching to a closed vty.
2209 * If we are in DDB, don't switch to a vty in the VT_PROCESS mode.
2210 * Note that we always allow the user to switch to the kernel
2211 * console even if it is closed.
2213 if ((sc_console == NULL) || (next_scr != sc_console->index)) {
2214 tp = VIRTUAL_TTY(sc, next_scr);
2215 if (!ISTTYOPEN(tp)) {
2217 sc_bell(cur_scp, bios_value.bell_pitch, BELL_DURATION);
2218 DPRINTF(5, ("error 2, requested vty isn't open!\n"));
2221 if ((debugger > 0) && (SC_STAT(tp->t_dev)->smode.mode == VT_PROCESS)) {
2223 DPRINTF(5, ("error 3, requested vty is in the VT_PROCESS mode\n"));
2228 /* this is the start of vty switching process... */
2229 ++sc->switch_in_progress;
2230 sc->delayed_next_scr = 0;
2231 sc->old_scp = cur_scp;
2232 sc->new_scp = SC_STAT(SC_DEV(sc, next_scr));
2233 if (sc->new_scp == sc->old_scp) {
2234 sc->switch_in_progress = 0;
2236 * XXX wakeup() calls mtx_lock(&sched_lock) which will hang if
2237 * sched_lock is in an in-between state, e.g., when we stop at
2238 * a breakpoint at fork_exit. It has always been wrong to call
2239 * wakeup() when the debugger is active. In RELENG_4, wakeup()
2240 * is supposed to be locked by splhigh(), but the debugger may
2241 * be invoked at splhigh().
2244 wakeup((caddr_t)&sc->new_scp->smode);
2246 DPRINTF(5, ("switch done (new == old)\n"));
2250 /* has controlling process died? */
2251 vt_proc_alive(sc->old_scp);
2252 vt_proc_alive(sc->new_scp);
2254 /* wait for the controlling process to release the screen, if necessary */
2255 if (signal_vt_rel(sc->old_scp)) {
2260 /* go set up the new vty screen */
2265 /* wake up processes waiting for this vty */
2267 wakeup((caddr_t)&sc->cur_scp->smode);
2269 /* wait for the controlling process to acknowledge, if necessary */
2270 if (signal_vt_acq(sc->cur_scp)) {
2275 sc->switch_in_progress = 0;
2276 if (sc->unit == sc_console_unit)
2277 cons_unavail = FALSE;
2279 DPRINTF(5, ("switch done\n"));
2285 do_switch_scr(sc_softc_t *sc, int s)
2287 vt_proc_alive(sc->new_scp);
2292 /* sc->cur_scp == sc->new_scp */
2293 wakeup((caddr_t)&sc->cur_scp->smode);
2295 /* wait for the controlling process to acknowledge, if necessary */
2296 if (!signal_vt_acq(sc->cur_scp)) {
2297 sc->switch_in_progress = 0;
2298 if (sc->unit == sc_console_unit)
2299 cons_unavail = FALSE;
2306 vt_proc_alive(scr_stat *scp)
2311 if ((p = pfind(scp->pid)) != NULL)
2316 scp->smode.mode = VT_AUTO;
2317 DPRINTF(5, ("vt controlling process %d died\n", scp->pid));
2323 signal_vt_rel(scr_stat *scp)
2325 if (scp->smode.mode != VT_PROCESS)
2327 scp->status |= SWITCH_WAIT_REL;
2328 PROC_LOCK(scp->proc);
2329 psignal(scp->proc, scp->smode.relsig);
2330 PROC_UNLOCK(scp->proc);
2331 DPRINTF(5, ("sending relsig to %d\n", scp->pid));
2336 signal_vt_acq(scr_stat *scp)
2338 if (scp->smode.mode != VT_PROCESS)
2340 if (scp->sc->unit == sc_console_unit)
2341 cons_unavail = TRUE;
2342 scp->status |= SWITCH_WAIT_ACQ;
2343 PROC_LOCK(scp->proc);
2344 psignal(scp->proc, scp->smode.acqsig);
2345 PROC_UNLOCK(scp->proc);
2346 DPRINTF(5, ("sending acqsig to %d\n", scp->pid));
2351 finish_vt_rel(scr_stat *scp, int release, int *s)
2353 if (scp == scp->sc->old_scp && scp->status & SWITCH_WAIT_REL) {
2354 scp->status &= ~SWITCH_WAIT_REL;
2356 *s = do_switch_scr(scp->sc, *s);
2358 scp->sc->switch_in_progress = 0;
2365 finish_vt_acq(scr_stat *scp)
2367 if (scp == scp->sc->new_scp && scp->status & SWITCH_WAIT_ACQ) {
2368 scp->status &= ~SWITCH_WAIT_ACQ;
2369 scp->sc->switch_in_progress = 0;
2376 exchange_scr(sc_softc_t *sc)
2380 /* save the current state of video and keyboard */
2381 sc_move_cursor(sc->old_scp, sc->old_scp->xpos, sc->old_scp->ypos);
2382 if (!ISGRAPHSC(sc->old_scp))
2383 sc_remove_cursor_image(sc->old_scp);
2384 if (sc->old_scp->kbd_mode == K_XLATE)
2385 save_kbd_state(sc->old_scp);
2387 /* set up the video for the new screen */
2388 scp = sc->cur_scp = sc->new_scp;
2389 if (sc->old_scp->mode != scp->mode || ISUNKNOWNSC(sc->old_scp))
2392 sc_vtb_init(&scp->scr, VTB_FRAMEBUFFER, scp->xsize, scp->ysize,
2393 (void *)sc->adp->va_window, FALSE);
2394 scp->status |= MOUSE_HIDDEN;
2395 sc_move_cursor(scp, scp->xpos, scp->ypos);
2396 if (!ISGRAPHSC(scp))
2397 sc_set_cursor_image(scp);
2398 #ifndef SC_NO_PALETTE_LOADING
2399 if (ISGRAPHSC(sc->old_scp))
2400 load_palette(sc->adp, sc->palette);
2402 sc_set_border(scp, scp->border);
2404 /* set up the keyboard for the new screen */
2405 if (sc->old_scp->kbd_mode != scp->kbd_mode)
2406 kbd_ioctl(sc->kbd, KDSKBMODE, (caddr_t)&scp->kbd_mode);
2407 update_kbd_state(scp, scp->status, LOCK_MASK);
2413 sc_puts(scr_stat *scp, u_char *buf, int len)
2416 /* make screensaver happy */
2417 if (!sticky_splash && scp == scp->sc->cur_scp && !sc_saver_keyb_only)
2418 run_scrn_saver = FALSE;
2422 (*scp->tsw->te_puts)(scp, buf, len);
2424 if (scp->sc->delayed_next_scr)
2425 sc_switch_scr(scp->sc, scp->sc->delayed_next_scr - 1);
2429 sc_draw_cursor_image(scr_stat *scp)
2431 /* assert(scp == scp->sc->cur_scp); */
2432 ++scp->sc->videoio_in_progress;
2433 (*scp->rndr->draw_cursor)(scp, scp->cursor_pos,
2434 scp->curs_attr.flags & CONS_BLINK_CURSOR, TRUE,
2435 sc_inside_cutmark(scp, scp->cursor_pos));
2436 scp->cursor_oldpos = scp->cursor_pos;
2437 --scp->sc->videoio_in_progress;
2441 sc_remove_cursor_image(scr_stat *scp)
2443 /* assert(scp == scp->sc->cur_scp); */
2444 ++scp->sc->videoio_in_progress;
2445 (*scp->rndr->draw_cursor)(scp, scp->cursor_oldpos,
2446 scp->curs_attr.flags & CONS_BLINK_CURSOR, FALSE,
2447 sc_inside_cutmark(scp, scp->cursor_oldpos));
2448 --scp->sc->videoio_in_progress;
2452 update_cursor_image(scr_stat *scp)
2454 /* assert(scp == scp->sc->cur_scp); */
2455 sc_remove_cursor_image(scp);
2456 sc_set_cursor_image(scp);
2457 sc_draw_cursor_image(scp);
2461 sc_set_cursor_image(scr_stat *scp)
2463 scp->curs_attr.flags = scp->curr_curs_attr.flags;
2464 if (scp->curs_attr.flags & CONS_HIDDEN_CURSOR) {
2465 /* hidden cursor is internally represented as zero-height underline */
2466 scp->curs_attr.flags = CONS_CHAR_CURSOR;
2467 scp->curs_attr.base = scp->curs_attr.height = 0;
2468 } else if (scp->curs_attr.flags & CONS_CHAR_CURSOR) {
2469 scp->curs_attr.base = imin(scp->curr_curs_attr.base,
2470 scp->font_size - 1);
2471 scp->curs_attr.height = imin(scp->curr_curs_attr.height,
2472 scp->font_size - scp->curs_attr.base);
2473 } else { /* block cursor */
2474 scp->curs_attr.base = 0;
2475 scp->curs_attr.height = scp->font_size;
2478 /* assert(scp == scp->sc->cur_scp); */
2479 ++scp->sc->videoio_in_progress;
2480 (*scp->rndr->set_cursor)(scp, scp->curs_attr.base, scp->curs_attr.height,
2481 scp->curs_attr.flags & CONS_BLINK_CURSOR);
2482 --scp->sc->videoio_in_progress;
2486 change_cursor_shape(scr_stat *scp, int flags, int base, int height)
2488 if ((scp == scp->sc->cur_scp) && !ISGRAPHSC(scp))
2489 sc_remove_cursor_image(scp);
2492 scp->curr_curs_attr.base = base;
2494 scp->curr_curs_attr.height = height;
2495 if (flags & CONS_RESET_CURSOR)
2496 scp->curr_curs_attr = scp->dflt_curs_attr;
2498 scp->curr_curs_attr.flags = flags & CONS_CURSOR_ATTRS;
2500 if ((scp == scp->sc->cur_scp) && !ISGRAPHSC(scp)) {
2501 sc_set_cursor_image(scp);
2502 sc_draw_cursor_image(scp);
2507 sc_change_cursor_shape(scr_stat *scp, int flags, int base, int height)
2515 if ((flags != -1) && (flags & CONS_LOCAL_CURSOR)) {
2516 /* local (per vty) change */
2517 change_cursor_shape(scp, flags, base, height);
2525 sc->curs_attr.base = base;
2527 sc->curs_attr.height = height;
2529 if (flags & CONS_RESET_CURSOR)
2530 sc->curs_attr = sc->dflt_curs_attr;
2532 sc->curs_attr.flags = flags & CONS_CURSOR_ATTRS;
2535 for (i = sc->first_vty; i < sc->first_vty + sc->vtys; ++i) {
2536 if ((dev = SC_DEV(sc, i)) == NODEV)
2538 if ((scp = SC_STAT(dev)) == NULL)
2540 scp->dflt_curs_attr = sc->curs_attr;
2541 change_cursor_shape(scp, CONS_RESET_CURSOR, -1, -1);
2547 scinit(int unit, int flags)
2550 * When syscons is being initialized as the kernel console, malloc()
2551 * is not yet functional, because various kernel structures has not been
2552 * fully initialized yet. Therefore, we need to declare the following
2553 * static buffers for the console. This is less than ideal,
2554 * but is necessry evil for the time being. XXX
2556 static scr_stat main_console;
2557 static dev_t main_devs[MAXCONS];
2558 static struct tty main_tty;
2559 static u_short sc_buffer[ROW*COL]; /* XXX */
2560 #ifndef SC_NO_FONT_LOADING
2561 static u_char font_8[256*8];
2562 static u_char font_14[256*14];
2563 static u_char font_16[256*16];
2568 video_adapter_t *adp;
2573 /* one time initialization */
2574 if (init_done == COLD)
2575 sc_get_bios_values(&bios_value);
2579 * Allocate resources. Even if we are being called for the second
2580 * time, we must allocate them again, because they might have
2583 sc = sc_get_softc(unit, flags & SC_KERNEL_CONSOLE);
2585 if (sc->adapter >= 0) {
2586 vid_release(sc->adp, (void *)&sc->adapter);
2590 if (sc->keyboard >= 0) {
2591 DPRINTF(5, ("sc%d: releasing kbd%d\n", unit, sc->keyboard));
2592 i = kbd_release(sc->kbd, (void *)&sc->keyboard);
2593 DPRINTF(5, ("sc%d: kbd_release returned %d\n", unit, i));
2594 if (sc->kbd != NULL) {
2595 DPRINTF(5, ("sc%d: kbd != NULL!, index:%d, unit:%d, flags:0x%x\n",
2596 unit, sc->kbd->kb_index, sc->kbd->kb_unit, sc->kbd->kb_flags));
2600 sc->adapter = vid_allocate("*", unit, (void *)&sc->adapter);
2601 sc->adp = vid_get_adapter(sc->adapter);
2602 /* assert((sc->adapter >= 0) && (sc->adp != NULL)) */
2603 sc->keyboard = kbd_allocate("*", unit, (void *)&sc->keyboard,
2605 DPRINTF(1, ("sc%d: keyboard %d\n", unit, sc->keyboard));
2606 sc->kbd = kbd_get_keyboard(sc->keyboard);
2607 if (sc->kbd != NULL) {
2608 DPRINTF(1, ("sc%d: kbd index:%d, unit:%d, flags:0x%x\n",
2609 unit, sc->kbd->kb_index, sc->kbd->kb_unit, sc->kbd->kb_flags));
2612 if (!(sc->flags & SC_INIT_DONE) || (adp != sc->adp)) {
2614 sc->initial_mode = sc->adp->va_initial_mode;
2616 #ifndef SC_NO_FONT_LOADING
2617 if (flags & SC_KERNEL_CONSOLE) {
2618 sc->font_8 = font_8;
2619 sc->font_14 = font_14;
2620 sc->font_16 = font_16;
2621 } else if (sc->font_8 == NULL) {
2622 /* assert(sc_malloc) */
2623 sc->font_8 = malloc(sizeof(font_8), M_DEVBUF, M_WAITOK);
2624 sc->font_14 = malloc(sizeof(font_14), M_DEVBUF, M_WAITOK);
2625 sc->font_16 = malloc(sizeof(font_16), M_DEVBUF, M_WAITOK);
2629 /* extract the hardware cursor location and hide the cursor for now */
2630 (*vidsw[sc->adapter]->read_hw_cursor)(sc->adp, &col, &row);
2631 (*vidsw[sc->adapter]->set_hw_cursor)(sc->adp, -1, -1);
2633 /* set up the first console */
2634 sc->first_vty = unit*MAXCONS;
2635 sc->vtys = MAXCONS; /* XXX: should be configurable */
2636 if (flags & SC_KERNEL_CONSOLE) {
2637 sc->dev = main_devs;
2638 sc->dev[0] = makedev(CDEV_MAJOR, unit*MAXCONS);
2639 sc->dev[0]->si_tty = &main_tty;
2640 ttyregister(&main_tty);
2641 scp = &main_console;
2642 init_scp(sc, sc->first_vty, scp);
2643 sc_vtb_init(&scp->vtb, VTB_MEMORY, scp->xsize, scp->ysize,
2644 (void *)sc_buffer, FALSE);
2645 if (sc_init_emulator(scp, SC_DFLT_TERM))
2646 sc_init_emulator(scp, "*");
2647 (*scp->tsw->te_default_attr)(scp,
2648 kernel_default.std_color,
2649 kernel_default.rev_color);
2651 /* assert(sc_malloc) */
2652 sc->dev = malloc(sizeof(dev_t)*sc->vtys, M_DEVBUF, M_WAITOK|M_ZERO);
2653 sc->dev[0] = makedev(CDEV_MAJOR, unit*MAXCONS);
2654 sc->dev[0]->si_tty = ttymalloc(sc->dev[0]->si_tty);
2655 scp = alloc_scp(sc, sc->first_vty);
2657 SC_STAT(sc->dev[0]) = scp;
2660 /* copy screen to temporary buffer */
2661 sc_vtb_init(&scp->scr, VTB_FRAMEBUFFER, scp->xsize, scp->ysize,
2662 (void *)scp->sc->adp->va_window, FALSE);
2664 sc_vtb_copy(&scp->scr, 0, &scp->vtb, 0, scp->xsize*scp->ysize);
2666 /* move cursors to the initial positions */
2667 if (col >= scp->xsize)
2669 if (row >= scp->ysize)
2670 row = scp->ysize - 1;
2673 scp->cursor_pos = scp->cursor_oldpos = row*scp->xsize + col;
2675 if (bios_value.cursor_end < scp->font_size)
2676 sc->dflt_curs_attr.base = scp->font_size -
2677 bios_value.cursor_end - 1;
2679 sc->dflt_curs_attr.base = 0;
2680 i = bios_value.cursor_end - bios_value.cursor_start + 1;
2681 sc->dflt_curs_attr.height = imin(i, scp->font_size);
2682 sc->dflt_curs_attr.flags = 0;
2683 sc->curs_attr = sc->dflt_curs_attr;
2684 scp->curr_curs_attr = scp->dflt_curs_attr = sc->curs_attr;
2686 #ifndef SC_NO_SYSMOUSE
2687 sc_mouse_move(scp, scp->xpixel/2, scp->ypixel/2);
2689 if (!ISGRAPHSC(scp)) {
2690 sc_set_cursor_image(scp);
2691 sc_draw_cursor_image(scp);
2694 /* save font and palette */
2695 #ifndef SC_NO_FONT_LOADING
2696 sc->fonts_loaded = 0;
2697 if (ISFONTAVAIL(sc->adp->va_flags)) {
2699 bcopy(dflt_font_8, sc->font_8, sizeof(dflt_font_8));
2700 bcopy(dflt_font_14, sc->font_14, sizeof(dflt_font_14));
2701 bcopy(dflt_font_16, sc->font_16, sizeof(dflt_font_16));
2702 sc->fonts_loaded = FONT_16 | FONT_14 | FONT_8;
2703 if (scp->font_size < 14) {
2704 sc_load_font(scp, 0, 8, sc->font_8, 0, 256);
2705 } else if (scp->font_size >= 16) {
2706 sc_load_font(scp, 0, 16, sc->font_16, 0, 256);
2708 sc_load_font(scp, 0, 14, sc->font_14, 0, 256);
2710 #else /* !SC_DFLT_FONT */
2711 if (scp->font_size < 14) {
2712 sc_save_font(scp, 0, 8, sc->font_8, 0, 256);
2713 sc->fonts_loaded = FONT_8;
2714 } else if (scp->font_size >= 16) {
2715 sc_save_font(scp, 0, 16, sc->font_16, 0, 256);
2716 sc->fonts_loaded = FONT_16;
2718 sc_save_font(scp, 0, 14, sc->font_14, 0, 256);
2719 sc->fonts_loaded = FONT_14;
2721 #endif /* SC_DFLT_FONT */
2722 /* FONT KLUDGE: always use the font page #0. XXX */
2723 sc_show_font(scp, 0);
2725 #endif /* !SC_NO_FONT_LOADING */
2727 #ifndef SC_NO_PALETTE_LOADING
2728 save_palette(sc->adp, sc->palette);
2732 if (!(sc->flags & SC_SPLASH_SCRN) && (flags & SC_KERNEL_CONSOLE)) {
2733 /* we are ready to put up the splash image! */
2734 splash_init(sc->adp, scsplash_callback, sc);
2735 sc->flags |= SC_SPLASH_SCRN;
2740 /* the rest is not necessary, if we have done it once */
2741 if (sc->flags & SC_INIT_DONE)
2744 /* initialize mapscrn arrays to a one to one map */
2745 for (i = 0; i < sizeof(sc->scr_map); i++)
2746 sc->scr_map[i] = sc->scr_rmap[i] = i;
2748 sc->flags |= SC_INIT_DONE;
2751 #if __i386__ || __ia64__
2753 scterm(int unit, int flags)
2758 sc = sc_get_softc(unit, flags & SC_KERNEL_CONSOLE);
2760 return; /* shouldn't happen */
2763 /* this console is no longer available for the splash screen */
2764 if (sc->flags & SC_SPLASH_SCRN) {
2765 splash_term(sc->adp);
2766 sc->flags &= ~SC_SPLASH_SCRN;
2771 /* move the hardware cursor to the upper-left corner */
2772 (*vidsw[sc->adapter]->set_hw_cursor)(sc->adp, 0, 0);
2775 /* release the keyboard and the video card */
2776 if (sc->keyboard >= 0)
2777 kbd_release(sc->kbd, &sc->keyboard);
2778 if (sc->adapter >= 0)
2779 vid_release(sc->adp, &sc->adapter);
2781 /* stop the terminal emulator, if any */
2782 scp = SC_STAT(sc->dev[0]);
2784 (*scp->tsw->te_term)(scp, &scp->ts);
2785 if (scp->ts != NULL)
2786 free(scp->ts, M_DEVBUF);
2788 /* clear the structure */
2789 if (!(flags & SC_KERNEL_CONSOLE)) {
2790 /* XXX: We need delete_dev() for this */
2791 free(sc->dev, M_DEVBUF);
2793 /* XXX: We need a ttyunregister for this */
2794 free(sc->tty, M_DEVBUF);
2796 #ifndef SC_NO_FONT_LOADING
2797 free(sc->font_8, M_DEVBUF);
2798 free(sc->font_14, M_DEVBUF);
2799 free(sc->font_16, M_DEVBUF);
2801 /* XXX vtb, history */
2803 bzero(sc, sizeof(*sc));
2810 scshutdown(void *arg, int howto)
2812 /* assert(sc_console != NULL) */
2814 sc_touch_scrn_saver();
2815 if (!cold && sc_console
2816 && sc_console->sc->cur_scp->smode.mode == VT_AUTO
2817 && sc_console->smode.mode == VT_AUTO)
2818 sc_switch_scr(sc_console->sc, sc_console->index);
2819 shutdown_in_progress = TRUE;
2823 sc_clean_up(scr_stat *scp)
2829 if (scp->sc->flags & SC_SCRN_BLANKED) {
2830 sc_touch_scrn_saver();
2832 if ((error = wait_scrn_saver_stop(scp->sc)))
2836 scp->status |= MOUSE_HIDDEN;
2837 sc_remove_mouse_image(scp);
2838 sc_remove_cutmarking(scp);
2843 sc_alloc_scr_buffer(scr_stat *scp, int wait, int discard)
2849 sc_vtb_init(&new, VTB_MEMORY, scp->xsize, scp->ysize, NULL, wait);
2850 if (!discard && (old.vtb_flags & VTB_VALID)) {
2851 /* retain the current cursor position and buffer contants */
2852 scp->cursor_oldpos = scp->cursor_pos;
2854 * This works only if the old buffer has the same size as or larger
2855 * than the new one. XXX
2857 sc_vtb_copy(&old, 0, &new, 0, scp->xsize*scp->ysize);
2861 sc_vtb_destroy(&old);
2864 #ifndef SC_NO_SYSMOUSE
2865 /* move the mouse cursor at the center of the screen */
2866 sc_mouse_move(scp, scp->xpixel / 2, scp->ypixel / 2);
2871 *alloc_scp(sc_softc_t *sc, int vty)
2875 /* assert(sc_malloc) */
2877 scp = (scr_stat *)malloc(sizeof(scr_stat), M_DEVBUF, M_WAITOK);
2878 init_scp(sc, vty, scp);
2880 sc_alloc_scr_buffer(scp, TRUE, TRUE);
2881 if (sc_init_emulator(scp, SC_DFLT_TERM))
2882 sc_init_emulator(scp, "*");
2884 #ifndef SC_NO_CUTPASTE
2885 sc_alloc_cut_buffer(scp, TRUE);
2888 #ifndef SC_NO_HISTORY
2889 sc_alloc_history_buffer(scp, 0, 0, TRUE);
2896 init_scp(sc_softc_t *sc, int vty, scr_stat *scp)
2900 bzero(scp, sizeof(*scp));
2905 scp->mode = sc->initial_mode;
2906 (*vidsw[sc->adapter]->get_info)(sc->adp, scp->mode, &info);
2907 if (info.vi_flags & V_INFO_GRAPHICS) {
2908 scp->status |= GRAPHICS_MODE;
2909 scp->xpixel = info.vi_width;
2910 scp->ypixel = info.vi_height;
2911 scp->xsize = info.vi_width/info.vi_cwidth;
2912 scp->ysize = info.vi_height/info.vi_cheight;
2916 scp->xsize = info.vi_width;
2917 scp->ysize = info.vi_height;
2918 scp->xpixel = scp->xsize*info.vi_cwidth;
2919 scp->ypixel = scp->ysize*info.vi_cheight;
2920 if (info.vi_cheight < 14) {
2922 #ifndef SC_NO_FONT_LOADING
2923 scp->font = sc->font_8;
2927 } else if (info.vi_cheight >= 16) {
2928 scp->font_size = 16;
2929 #ifndef SC_NO_FONT_LOADING
2930 scp->font = sc->font_16;
2935 scp->font_size = 14;
2936 #ifndef SC_NO_FONT_LOADING
2937 scp->font = sc->font_14;
2943 sc_vtb_init(&scp->vtb, VTB_MEMORY, 0, 0, NULL, FALSE);
2944 sc_vtb_init(&scp->scr, VTB_FRAMEBUFFER, 0, 0, NULL, FALSE);
2945 scp->xoff = scp->yoff = 0;
2946 scp->xpos = scp->ypos = 0;
2947 scp->start = scp->xsize * scp->ysize - 1;
2952 scp->border = BG_BLACK;
2953 scp->curr_curs_attr = scp->dflt_curs_attr = sc->curs_attr;
2954 scp->mouse_cut_start = scp->xsize*scp->ysize;
2955 scp->mouse_cut_end = -1;
2956 scp->mouse_signal = 0;
2958 scp->mouse_proc = NULL;
2959 scp->kbd_mode = K_XLATE;
2960 scp->bell_pitch = bios_value.bell_pitch;
2961 scp->bell_duration = BELL_DURATION;
2962 scp->status |= (bios_value.shift_state & NLKED);
2963 scp->status |= CURSOR_ENABLED | MOUSE_HIDDEN;
2966 scp->smode.mode = VT_AUTO;
2967 scp->history = NULL;
2968 scp->history_pos = 0;
2969 scp->history_size = 0;
2973 sc_init_emulator(scr_stat *scp, char *name)
2980 if (name == NULL) /* if no name is given, use the current emulator */
2982 else /* ...otherwise find the named emulator */
2983 sw = sc_term_match(name);
2988 if (strcmp(sw->te_renderer, "*") != 0) {
2989 rndr = sc_render_match(scp, sw->te_renderer,
2990 scp->status & (GRAPHICS_MODE | PIXEL_MODE));
2993 rndr = sc_render_match(scp, scp->sc->adp->va_name,
2994 scp->status & (GRAPHICS_MODE | PIXEL_MODE));
2999 if (sw == scp->tsw) {
3000 error = (*sw->te_init)(scp, &scp->ts, SC_TE_WARM_INIT);
3002 sc_clear_screen(scp);
3003 /* assert(error == 0); */
3007 if (sc_malloc && (sw->te_size > 0))
3008 p = malloc(sw->te_size, M_DEVBUF, M_NOWAIT);
3011 error = (*sw->te_init)(scp, &p, SC_TE_COLD_INIT);
3016 (*scp->tsw->te_term)(scp, &scp->ts);
3017 if (scp->ts != NULL)
3018 free(scp->ts, M_DEVBUF);
3024 (*sw->te_default_attr)(scp, user_default.std_color, user_default.rev_color);
3025 sc_clear_screen(scp);
3031 * scgetc(flags) - get character from keyboard.
3032 * If flags & SCGETC_CN, then avoid harmful side effects.
3033 * If flags & SCGETC_NONBLOCK, then wait until a key is pressed, else
3034 * return NOKEY if there is nothing there.
3037 scgetc(sc_softc_t *sc, u_int flags)
3040 #ifndef SC_NO_HISTORY
3048 if (sc->kbd == NULL)
3053 /* I don't like this, but... XXX */
3054 if (flags & SCGETC_CN)
3055 sccnupdate(sc->cur_scp);
3058 /* first see if there is something in the keyboard port */
3060 c = kbd_read_char(sc->kbd, !(flags & SCGETC_NONBLOCK));
3062 if (!(flags & SCGETC_CN))
3063 sc_bell(scp, bios_value.bell_pitch, BELL_DURATION);
3064 } else if (c == NOKEY)
3070 /* make screensaver happy */
3072 sc_touch_scrn_saver();
3074 if (!(flags & SCGETC_CN))
3075 random_harvest(&c, sizeof(c), 1, 0, RANDOM_KEYBOARD);
3077 if (scp->kbd_mode != K_XLATE)
3080 /* if scroll-lock pressed allow history browsing */
3081 if (!ISGRAPHSC(scp) && scp->history && scp->status & SLKED) {
3083 scp->status &= ~CURSOR_ENABLED;
3084 sc_remove_cursor_image(scp);
3086 #ifndef SC_NO_HISTORY
3087 if (!(scp->status & BUFFER_SAVED)) {
3088 scp->status |= BUFFER_SAVED;
3092 /* FIXME: key codes */
3093 case SPCLKEY | FKEY | F(49): /* home key */
3094 sc_remove_cutmarking(scp);
3098 case SPCLKEY | FKEY | F(57): /* end key */
3099 sc_remove_cutmarking(scp);
3103 case SPCLKEY | FKEY | F(50): /* up arrow key */
3104 sc_remove_cutmarking(scp);
3105 if (sc_hist_up_line(scp))
3106 if (!(flags & SCGETC_CN))
3107 sc_bell(scp, bios_value.bell_pitch, BELL_DURATION);
3110 case SPCLKEY | FKEY | F(58): /* down arrow key */
3111 sc_remove_cutmarking(scp);
3112 if (sc_hist_down_line(scp))
3113 if (!(flags & SCGETC_CN))
3114 sc_bell(scp, bios_value.bell_pitch, BELL_DURATION);
3117 case SPCLKEY | FKEY | F(51): /* page up key */
3118 sc_remove_cutmarking(scp);
3119 for (i=0; i<scp->ysize; i++)
3120 if (sc_hist_up_line(scp)) {
3121 if (!(flags & SCGETC_CN))
3122 sc_bell(scp, bios_value.bell_pitch, BELL_DURATION);
3127 case SPCLKEY | FKEY | F(59): /* page down key */
3128 sc_remove_cutmarking(scp);
3129 for (i=0; i<scp->ysize; i++)
3130 if (sc_hist_down_line(scp)) {
3131 if (!(flags & SCGETC_CN))
3132 sc_bell(scp, bios_value.bell_pitch, BELL_DURATION);
3137 #endif /* SC_NO_HISTORY */
3141 * Process and consume special keys here. Return a plain char code
3142 * or a char code with the META flag or a function key code.
3146 /* goto next_code */
3151 switch (KEYCHAR(c)) {
3153 case NLK: case CLK: case ALK:
3156 kbd_ioctl(sc->kbd, KDGKBSTATE, (caddr_t)&f);
3158 scp->status |= SLKED;
3160 if (scp->status & SLKED) {
3161 scp->status &= ~SLKED;
3162 #ifndef SC_NO_HISTORY
3163 if (scp->status & BUFFER_SAVED) {
3164 if (!sc_hist_restore(scp))
3165 sc_remove_cutmarking(scp);
3166 scp->status &= ~BUFFER_SAVED;
3167 scp->status |= CURSOR_ENABLED;
3168 sc_draw_cursor_image(scp);
3170 tp = VIRTUAL_TTY(sc, scp->index);
3179 #ifndef SC_NO_CUTPASTE
3180 sc_mouse_paste(scp);
3184 /* NON-LOCKING KEYS */
3186 case LSH: case RSH: case LCTR: case RCTR:
3187 case LALT: case RALT: case ASH: case META:
3191 if (!(sc->flags & SC_SCRN_BLANKED))
3197 /* force activatation/deactivation of the screen saver */
3198 if (!(sc->flags & SC_SCRN_BLANKED)) {
3199 run_scrn_saver = TRUE;
3200 sc->scrn_time_stamp -= scrn_blank_time;
3204 * While devices are being probed, the screen saver need
3205 * to be invoked explictly. XXX
3207 if (sc->flags & SC_SCRN_BLANKED) {
3208 scsplash_stick(FALSE);
3209 stop_scrn_saver(sc, current_saver);
3211 if (!ISGRAPHSC(scp)) {
3212 scsplash_stick(TRUE);
3213 (*current_saver)(sc, TRUE);
3217 #endif /* DEV_SPLASH */
3221 #ifndef SC_DISABLE_REBOOT
3227 #ifndef SC_DISABLE_REBOOT
3228 shutdown_nice(RB_HALT);
3233 #ifndef SC_DISABLE_REBOOT
3234 shutdown_nice(RB_HALT|RB_POWEROFF);
3239 power_pm_suspend(POWER_SLEEP_STATE_SUSPEND);
3242 power_pm_suspend(POWER_SLEEP_STATE_STANDBY);
3246 #ifndef SC_DISABLE_DDBKEY
3248 Debugger("manual escape to debugger");
3250 printf("No debugger in kernel\n");
3252 #else /* SC_DISABLE_DDBKEY */
3254 #endif /* SC_DISABLE_DDBKEY */
3258 if (enable_panic_key)
3259 panic("Forced by the panic key");
3263 this_scr = scp->index;
3264 for (i = (this_scr - sc->first_vty + 1)%sc->vtys;
3265 sc->first_vty + i != this_scr;
3266 i = (i + 1)%sc->vtys) {
3267 struct tty *tp = VIRTUAL_TTY(sc, sc->first_vty + i);
3268 if (ISTTYOPEN(tp)) {
3269 sc_switch_scr(scp->sc, sc->first_vty + i);
3276 this_scr = scp->index;
3277 for (i = (this_scr - sc->first_vty + sc->vtys - 1)%sc->vtys;
3278 sc->first_vty + i != this_scr;
3279 i = (i + sc->vtys - 1)%sc->vtys) {
3280 struct tty *tp = VIRTUAL_TTY(sc, sc->first_vty + i);
3281 if (ISTTYOPEN(tp)) {
3282 sc_switch_scr(scp->sc, sc->first_vty + i);
3289 if (KEYCHAR(c) >= F_SCR && KEYCHAR(c) <= L_SCR) {
3290 sc_switch_scr(scp->sc, sc->first_vty + KEYCHAR(c) - F_SCR);
3293 /* assert(c & FKEY) */
3294 if (!(sc->flags & SC_SCRN_BLANKED))
3298 /* goto next_code */
3300 /* regular keys (maybe MKEY is set) */
3301 if (!(sc->flags & SC_SCRN_BLANKED))
3310 scmmap(dev_t dev, vm_offset_t offset, int nprot)
3315 if (scp != scp->sc->cur_scp)
3317 return (*vidsw[scp->sc->adapter]->mmap)(scp->sc->adp, offset, nprot);
3321 save_kbd_state(scr_stat *scp)
3326 error = kbd_ioctl(scp->sc->kbd, KDGKBSTATE, (caddr_t)&state);
3327 if (error == ENOIOCTL)
3330 scp->status &= ~LOCK_MASK;
3331 scp->status |= state;
3337 update_kbd_state(scr_stat *scp, int new_bits, int mask)
3342 if (mask != LOCK_MASK) {
3343 error = kbd_ioctl(scp->sc->kbd, KDGKBSTATE, (caddr_t)&state);
3344 if (error == ENOIOCTL)
3349 state |= new_bits & mask;
3351 state = new_bits & LOCK_MASK;
3353 error = kbd_ioctl(scp->sc->kbd, KDSKBSTATE, (caddr_t)&state);
3354 if (error == ENOIOCTL)
3360 update_kbd_leds(scr_stat *scp, int which)
3365 error = kbd_ioctl(scp->sc->kbd, KDSETLED, (caddr_t)&which);
3366 if (error == ENOIOCTL)
3372 set_mode(scr_stat *scp)
3376 /* reject unsupported mode */
3377 if ((*vidsw[scp->sc->adapter]->get_info)(scp->sc->adp, scp->mode, &info))
3380 /* if this vty is not currently showing, do nothing */
3381 if (scp != scp->sc->cur_scp)
3384 /* setup video hardware for the given mode */
3385 (*vidsw[scp->sc->adapter]->set_mode)(scp->sc->adp, scp->mode);
3386 sc_vtb_init(&scp->scr, VTB_FRAMEBUFFER, scp->xsize, scp->ysize,
3387 (void *)scp->sc->adp->va_window, FALSE);
3389 #ifndef SC_NO_FONT_LOADING
3390 /* load appropriate font */
3391 if (!(scp->status & GRAPHICS_MODE)) {
3392 if (!(scp->status & PIXEL_MODE) && ISFONTAVAIL(scp->sc->adp->va_flags)) {
3393 if (scp->font_size < 14) {
3394 if (scp->sc->fonts_loaded & FONT_8)
3395 sc_load_font(scp, 0, 8, scp->sc->font_8, 0, 256);
3396 } else if (scp->font_size >= 16) {
3397 if (scp->sc->fonts_loaded & FONT_16)
3398 sc_load_font(scp, 0, 16, scp->sc->font_16, 0, 256);
3400 if (scp->sc->fonts_loaded & FONT_14)
3401 sc_load_font(scp, 0, 14, scp->sc->font_14, 0, 256);
3405 * This is an interim kludge to display correct font.
3406 * Always use the font page #0 on the video plane 2.
3407 * Somehow we cannot show the font in other font pages on
3408 * some video cards... XXX
3410 sc_show_font(scp, 0);
3414 #endif /* !SC_NO_FONT_LOADING */
3416 sc_set_border(scp, scp->border);
3417 sc_set_cursor_image(scp);
3423 sc_set_border(scr_stat *scp, int color)
3425 ++scp->sc->videoio_in_progress;
3426 (*scp->rndr->draw_border)(scp, color);
3427 --scp->sc->videoio_in_progress;
3430 #ifndef SC_NO_FONT_LOADING
3432 sc_load_font(scr_stat *scp, int page, int size, u_char *buf,
3433 int base, int count)
3438 sc->font_loading_in_progress = TRUE;
3439 (*vidsw[sc->adapter]->load_font)(sc->adp, page, size, buf, base, count);
3440 sc->font_loading_in_progress = FALSE;
3444 sc_save_font(scr_stat *scp, int page, int size, u_char *buf,
3445 int base, int count)
3450 sc->font_loading_in_progress = TRUE;
3451 (*vidsw[sc->adapter]->save_font)(sc->adp, page, size, buf, base, count);
3452 sc->font_loading_in_progress = FALSE;
3456 sc_show_font(scr_stat *scp, int page)
3458 (*vidsw[scp->sc->adapter]->show_font)(scp->sc->adp, page);
3460 #endif /* !SC_NO_FONT_LOADING */
3463 sc_paste(scr_stat *scp, u_char *p, int count)
3468 tp = VIRTUAL_TTY(scp->sc, scp->sc->cur_scp->index);
3471 rmap = scp->sc->scr_rmap;
3472 for (; count > 0; --count)
3473 (*linesw[tp->t_line].l_rint)(rmap[*p++], tp);
3477 sc_bell(scr_stat *scp, int pitch, int duration)
3479 if (cold || shutdown_in_progress)
3482 if (scp != scp->sc->cur_scp && (scp->sc->flags & SC_QUIET_BELL))
3485 if (scp->sc->flags & SC_VISUAL_BELL) {
3486 if (scp->sc->blink_in_progress)
3488 scp->sc->blink_in_progress = 3;
3489 if (scp != scp->sc->cur_scp)
3490 scp->sc->blink_in_progress += 2;
3491 blink_screen(scp->sc->cur_scp);
3493 if (scp != scp->sc->cur_scp)
3495 sysbeep(pitch, duration);
3500 blink_screen(void *arg)
3502 scr_stat *scp = arg;
3505 if (ISGRAPHSC(scp) || (scp->sc->blink_in_progress <= 1)) {
3506 scp->sc->blink_in_progress = 0;
3508 tp = VIRTUAL_TTY(scp->sc, scp->index);
3511 if (scp->sc->delayed_next_scr)
3512 sc_switch_scr(scp->sc, scp->sc->delayed_next_scr - 1);
3515 (*scp->rndr->draw)(scp, 0, scp->xsize*scp->ysize,
3516 scp->sc->blink_in_progress & 1);
3517 scp->sc->blink_in_progress--;
3518 timeout(blink_screen, scp, hz / 10);