2 * Copyright (c) 1992-1998 Søren Schmidt
5 * This code is derived from software contributed to The DragonFly Project
6 * by Sascha Wildner <saw@online.de>
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
11 * 1. Redistributions of source code must retain the above copyright
12 * notice, this list of conditions and the following disclaimer,
13 * without modification, immediately at the beginning of the file.
14 * 2. Redistributions in binary form must reproduce the above copyright
15 * notice, this list of conditions and the following disclaimer in the
16 * documentation and/or other materials provided with the distribution.
17 * 3. The name of the author may not be used to endorse or promote products
18 * derived from this software without specific prior written permission.
20 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
21 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
22 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
23 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
24 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
25 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
26 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
27 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
28 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
29 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31 * $FreeBSD: /usr/local/www/cvsroot/FreeBSD/src/sys/dev/syscons/syscons.c,v 1.336.2.17 2004/03/25 08:41:09 ru Exp $
32 * $DragonFly: src/sys/dev/misc/syscons/syscons.c,v 1.35 2008/08/10 19:47:31 swildner Exp $
35 #include "use_splash.h"
36 #include "opt_syscons.h"
42 #include <sys/param.h>
43 #include <sys/systm.h>
44 #include <sys/eventhandler.h>
45 #include <sys/reboot.h>
49 #include <sys/signalvar.h>
50 #include <sys/sysctl.h>
52 #include <sys/kernel.h>
54 #include <sys/random.h>
55 #include <sys/thread2.h>
57 #include <machine/clock.h>
58 #include <machine/console.h>
59 #include <machine/psl.h>
60 #include <machine/pc/display.h>
62 #include <machine/apm_bios.h>
64 #include <machine/frame.h>
66 #include <dev/misc/kbd/kbdreg.h>
67 #include <dev/video/fb/fbreg.h>
68 #include <dev/video/fb/splashreg.h>
74 #define DEFAULT_BLANKTIME (5*60) /* 5 minutes */
75 #define MAX_BLANKTIME (7*24*60*60) /* 7 days!? */
77 #define KEYCODE_BS 0x0e /* "<-- Backspace" key, XXX */
79 MALLOC_DEFINE(M_SYSCONS, "syscons", "Syscons");
81 typedef struct default_attr {
82 int std_color; /* normal hardware color */
83 int rev_color; /* reverse hardware color */
86 static default_attr user_default = {
91 static default_attr kernel_default = {
93 SC_KERNEL_CONS_REV_ATTR,
96 static int sc_console_unit = -1;
97 static scr_stat *sc_console;
98 static struct tty *sc_console_tty;
99 static void *kernel_console_ts;
101 static char init_done = COLD;
102 static char shutdown_in_progress = FALSE;
103 static char sc_malloc = FALSE;
105 static int saver_mode = CONS_NO_SAVER; /* LKM/user saver */
106 static int run_scrn_saver = FALSE; /* should run the saver? */
107 static long scrn_blank_time = 0; /* screen saver timeout value */
109 static int scrn_blanked; /* # of blanked screen */
110 static int sticky_splash = FALSE;
112 static void none_saver(sc_softc_t *sc, int blank) { }
113 static void (*current_saver)(sc_softc_t *, int) = none_saver;
116 #if !defined(SC_NO_FONT_LOADING) && defined(SC_DFLT_FONT)
120 static bios_values_t bios_value;
122 static int enable_panic_key;
123 SYSCTL_INT(_machdep, OID_AUTO, enable_panic_key, CTLFLAG_RW, &enable_panic_key,
126 #define SC_CONSOLECTL 255
128 #define VIRTUAL_TTY(sc, x) ((SC_DEV((sc),(x)) != NULL) ? \
129 (SC_DEV((sc),(x))->si_tty) : NULL)
130 #define ISTTYOPEN(tp) ((tp) && ((tp)->t_state & TS_ISOPEN))
133 static cdev_t cctl_dev;
136 static int scvidprobe(int unit, int flags, int cons);
137 static int sckbdprobe(int unit, int flags, int cons);
138 static void scmeminit(void *arg);
139 static int scdevtounit(cdev_t dev);
140 static kbd_callback_func_t sckbdevent;
141 static int scparam(struct tty *tp, struct termios *t);
142 static void scstart(struct tty *tp);
143 static void scinit(int unit, int flags);
144 static void scterm(int unit, int flags);
145 static void scshutdown(void *arg, int howto);
146 static u_int scgetc(sc_softc_t *sc, u_int flags);
148 #define SCGETC_NONBLOCK 2
149 static int sccngetch(int flags);
150 static void sccnupdate(scr_stat *scp);
151 static scr_stat *alloc_scp(sc_softc_t *sc, int vty);
152 static void init_scp(sc_softc_t *sc, int vty, scr_stat *scp);
153 static timeout_t scrn_timer;
154 static int and_region(int *s1, int *e1, int s2, int e2);
155 static void scrn_update(scr_stat *scp, int show_cursor);
158 static int scsplash_callback(int event, void *arg);
159 static void scsplash_saver(sc_softc_t *sc, int show);
160 static int add_scrn_saver(void (*this_saver)(sc_softc_t *, int));
161 static int remove_scrn_saver(void (*this_saver)(sc_softc_t *, int));
162 static int set_scrn_saver_mode(scr_stat *scp, int mode, u_char *pal, int border);
163 static int restore_scrn_saver_mode(scr_stat *scp, int changemode);
164 static void stop_scrn_saver(sc_softc_t *sc, void (*saver)(sc_softc_t *, int));
165 static int wait_scrn_saver_stop(sc_softc_t *sc);
166 #define scsplash_stick(stick) (sticky_splash = (stick))
168 #define scsplash_stick(stick)
171 static void do_switch_scr(sc_softc_t *sc);
172 static int vt_proc_alive(scr_stat *scp);
173 static int signal_vt_rel(scr_stat *scp);
174 static int signal_vt_acq(scr_stat *scp);
175 static int finish_vt_rel(scr_stat *scp, int release);
176 static int finish_vt_acq(scr_stat *scp);
177 static void exchange_scr(sc_softc_t *sc);
178 static void update_cursor_image(scr_stat *scp);
179 static int save_kbd_state(scr_stat *scp);
180 static int update_kbd_state(scr_stat *scp, int state, int mask);
181 static int update_kbd_leds(scr_stat *scp, int which);
182 static timeout_t blink_screen;
183 static int sc_allocate_keyboard(sc_softc_t *sc, int unit);
185 #define CDEV_MAJOR 12
187 static cn_probe_t sccnprobe;
188 static cn_init_t sccninit;
189 static cn_init_t sccninit_fini;
190 static cn_getc_t sccngetc;
191 static cn_checkc_t sccncheckc;
192 static cn_putc_t sccnputc;
193 static cn_dbctl_t sccndbctl;
194 static cn_term_t sccnterm;
196 CONS_DRIVER(sc, sccnprobe, sccninit, sccninit_fini, sccnterm,
197 sccngetc, sccncheckc, sccnputc, sccndbctl);
199 static d_open_t scopen;
200 static d_close_t scclose;
201 static d_read_t scread;
202 static d_ioctl_t scioctl;
203 static d_mmap_t scmmap;
205 static struct dev_ops sc_ops = {
206 { "sc", CDEV_MAJOR, D_TTY | D_KQFILTER },
214 .d_kqfilter = ttykqfilter,
215 .d_revoke = ttyrevoke
219 sc_probe_unit(int unit, int flags)
221 if (!scvidprobe(unit, flags, FALSE)) {
223 kprintf("sc%d: no video adapter found.\n", unit);
227 /* syscons will be attached even when there is no keyboard */
228 sckbdprobe(unit, flags, FALSE);
233 /* probe video adapters, return TRUE if found */
235 scvidprobe(int unit, int flags, int cons)
238 * Access the video adapter driver through the back door!
239 * Video adapter drivers need to be configured before syscons.
240 * However, when syscons is being probed as the low-level console,
241 * they have not been initialized yet. We force them to initialize
242 * themselves here. XXX
244 vid_configure(cons ? VIO_PROBE_ONLY : 0);
246 return (vid_find_adapter("*", unit) >= 0);
249 /* probe the keyboard, return TRUE if found */
251 sckbdprobe(int unit, int flags, int cons)
253 /* access the keyboard driver through the backdoor! */
254 kbd_configure(cons ? KB_CONF_PROBE_ONLY : 0);
256 return (kbd_find_keyboard("*", unit) >= 0);
260 adapter_name(video_adapter_t *adp)
266 { KD_MONO, { "MDA", "MDA" } },
267 { KD_HERCULES, { "Hercules", "Hercules" } },
268 { KD_CGA, { "CGA", "CGA" } },
269 { KD_EGA, { "EGA", "EGA (mono)" } },
270 { KD_VGA, { "VGA", "VGA (mono)" } },
271 { KD_TGA, { "TGA", "TGA" } },
272 { -1, { "Unknown", "Unknown" } },
276 for (i = 0; names[i].type != -1; ++i)
277 if (names[i].type == adp->va_type)
279 return names[i].name[(adp->va_flags & V_ADP_COLOR) ? 0 : 1];
283 sc_attach_unit(int unit, int flags)
293 flags &= ~SC_KERNEL_CONSOLE;
295 if (sc_console_unit == unit) {
297 * If this unit is being used as the system console, we need to
298 * adjust some variables and buffers before and after scinit().
300 /* assert(sc_console != NULL) */
301 flags |= SC_KERNEL_CONSOLE;
306 if (sc_console->tsw->te_size > 0) {
307 /* assert(sc_console->ts != NULL); */
308 kernel_console_ts = sc_console->ts;
309 sc_console->ts = kmalloc(sc_console->tsw->te_size,
310 M_SYSCONS, M_WAITOK);
311 bcopy(kernel_console_ts, sc_console->ts, sc_console->tsw->te_size);
312 (*sc_console->tsw->te_default_attr)(sc_console,
313 user_default.std_color,
314 user_default.rev_color);
320 sc = sc_get_softc(unit, flags & SC_KERNEL_CONSOLE);
323 * If this is the console we couldn't setup sc->dev before because
324 * malloc wasn't working. Set it up now.
326 if (flags & SC_KERNEL_CONSOLE) {
327 KKASSERT(sc->dev == NULL);
328 sc->dev = kmalloc(sizeof(cdev_t)*sc->vtys, M_SYSCONS, M_WAITOK|M_ZERO);
329 sc->dev[0] = make_dev(&sc_ops, sc_console_unit*MAXCONS, UID_ROOT,
331 "ttyv%r", sc_console_unit*MAXCONS);
332 sc->dev[0]->si_tty = ttymalloc(sc->dev[0]->si_tty);
333 sc->dev[0]->si_drv1 = sc_console;
337 * Finish up the standard attach
340 callout_init(&sc->scrn_timer_ch);
341 scp = SC_STAT(sc->dev[0]);
342 if (sc_console == NULL) /* sc_console_unit < 0 */
346 if ((sc->config & SC_VESA800X600)
347 && ((*vidsw[sc->adapter]->get_info)(sc->adp, M_VESA_800x600, &info) == 0)) {
349 if (sc->flags & SC_SPLASH_SCRN)
350 splash_term(sc->adp);
352 sc_set_graphics_mode(scp, NULL, M_VESA_800x600);
353 sc_set_pixel_mode(scp, NULL, COL, ROW, 16);
354 sc->initial_mode = M_VESA_800x600;
356 /* put up the splash again! */
357 if (sc->flags & SC_SPLASH_SCRN)
358 splash_init(sc->adp, scsplash_callback, sc);
361 #endif /* SC_PIXEL_MODE */
363 /* initialize cursor */
365 update_cursor_image(scp);
367 /* get screen update going */
370 /* set up the keyboard */
371 kbd_ioctl(sc->kbd, KDSKBMODE, (caddr_t)&scp->kbd_mode);
372 update_kbd_state(scp, scp->status, LOCK_MASK);
374 kprintf("sc%d: %s <%d virtual consoles, flags=0x%x>\n",
375 unit, adapter_name(sc->adp), sc->vtys, sc->config);
377 kprintf("sc%d:", unit);
378 if (sc->adapter >= 0)
379 kprintf(" fb%d", sc->adapter);
380 if (sc->keyboard >= 0)
381 kprintf(", kbd%d", sc->keyboard);
383 kprintf(", terminal emulator: %s (%s)",
384 scp->tsw->te_name, scp->tsw->te_desc);
388 /* register a shutdown callback for the kernel console */
389 if (sc_console_unit == unit)
390 EVENTHANDLER_REGISTER(shutdown_pre_sync, scshutdown,
391 (void *)(uintptr_t)unit, SHUTDOWN_PRI_DEFAULT);
396 * The first vty already has struct tty and scr_stat initialized
397 * in scinit(). The other vtys will have these structs when
400 for (vc = 1; vc < sc->vtys; vc++) {
401 dev = make_dev(&sc_ops, vc + unit * MAXCONS,
403 0600, "ttyv%r", vc + unit * MAXCONS);
406 cctl_dev = make_dev(&sc_ops, SC_CONSOLECTL,
407 UID_ROOT, GID_WHEEL, 0600, "consolectl");
408 cctl_dev->si_tty = sc_console_tty = ttymalloc(sc_console_tty);
409 cctl_dev->si_drv1 = sc_console;
421 * As soon as malloc() becomes functional, we had better allocate
422 * various buffers for the kernel console.
425 if (sc_console_unit < 0) /* sc_console == NULL */
428 /* copy the temporary buffer to the final buffer */
429 sc_alloc_scr_buffer(sc_console, TRUE, FALSE);
431 #ifndef SC_NO_CUTPASTE
432 sc_alloc_cut_buffer(sc_console, TRUE);
435 #ifndef SC_NO_HISTORY
436 /* initialize history buffer & pointers */
437 sc_alloc_history_buffer(sc_console, 0, 0, TRUE);
441 SYSINIT(sc_mem, SI_BOOT1_POST, SI_ORDER_ANY, scmeminit, NULL);
444 scdevtounit(cdev_t dev)
446 int vty = SC_VTY(dev);
448 if (vty == SC_CONSOLECTL)
449 return ((sc_console != NULL) ? sc_console->sc->unit : -1);
450 else if ((vty < 0) || (vty >= MAXCONS*sc_max_unit()))
457 scopen(struct dev_open_args *ap)
459 cdev_t dev = ap->a_head.a_dev;
460 int unit = scdevtounit(dev);
467 DPRINTF(5, ("scopen: dev:%d,%d, unit:%d, vty:%d\n",
468 major(dev), minor(dev), unit, SC_VTY(dev)));
470 sc = sc_get_softc(unit, (sc_console_unit == unit) ? SC_KERNEL_CONSOLE : 0);
474 tp = dev->si_tty = ttymalloc(dev->si_tty);
475 tp->t_oproc = scstart;
476 tp->t_param = scparam;
477 tp->t_stop = nottystop;
481 if (!ISTTYOPEN(tp)) {
483 /* Use the current setting of the <-- key as default VERASE. */
484 /* If the Delete key is preferable, an stty is necessary */
485 if (sc->kbd != NULL) {
486 key.keynum = KEYCODE_BS;
487 kbd_ioctl(sc->kbd, GIO_KEYMAPENT, (caddr_t)&key);
488 tp->t_cc[VERASE] = key.key.map[0];
490 tp->t_iflag = TTYDEF_IFLAG;
491 tp->t_oflag = TTYDEF_OFLAG;
492 tp->t_cflag = TTYDEF_CFLAG;
493 tp->t_lflag = TTYDEF_LFLAG;
494 tp->t_ispeed = tp->t_ospeed = TTYDEF_SPEED;
495 scparam(tp, &tp->t_termios);
496 (*linesw[tp->t_line].l_modem)(tp, 1);
499 if (tp->t_state & TS_XCLUDE && priv_check_cred(ap->a_cred, PRIV_ROOT, 0))
502 error = (*linesw[tp->t_line].l_open)(dev, tp);
506 scp = dev->si_drv1 = alloc_scp(sc, SC_VTY(dev));
508 sc_set_pixel_mode(scp, NULL, COL, ROW, 16);
510 if (!tp->t_winsize.ws_col && !tp->t_winsize.ws_row) {
511 tp->t_winsize.ws_col = scp->xsize;
512 tp->t_winsize.ws_row = scp->ysize;
519 scclose(struct dev_close_args *ap)
521 cdev_t dev = ap->a_head.a_dev;
522 struct tty *tp = dev->si_tty;
526 if (SC_VTY(dev) != SC_CONSOLECTL) {
527 scp = SC_STAT(tp->t_dev);
528 /* were we in the middle of the VT switching process? */
529 DPRINTF(5, ("sc%d: scclose(), ", scp->sc->unit));
530 if ((scp == scp->sc->cur_scp) && (scp->sc->unit == sc_console_unit))
531 cons_unavail = FALSE;
533 * note: must be called from a critical section because finish_vt_rel
534 * will call do_switch_scr which releases it temporarily
536 if (finish_vt_rel(scp, TRUE) == 0) /* force release */
537 DPRINTF(5, ("reset WAIT_REL, "));
538 if (finish_vt_acq(scp) == 0) /* force acknowledge */
539 DPRINTF(5, ("reset WAIT_ACQ, "));
541 if (scp == &main_console) {
544 scp->smode.mode = VT_AUTO;
547 sc_vtb_destroy(&scp->vtb);
548 sc_vtb_destroy(&scp->scr);
549 sc_free_history_buffer(scp, scp->ysize);
551 kfree(scp, M_SYSCONS);
556 scp->smode.mode = VT_AUTO;
558 scp->kbd_mode = K_XLATE;
559 if (scp == scp->sc->cur_scp)
560 kbd_ioctl(scp->sc->kbd, KDSKBMODE, (caddr_t)&scp->kbd_mode);
561 DPRINTF(5, ("done.\n"));
563 (*linesw[tp->t_line].l_close)(tp, ap->a_fflag);
571 scread(struct dev_read_args *ap)
573 sc_touch_scrn_saver();
574 return (ttyread(ap));
578 sckbdevent(keyboard_t *thiskbd, int event, void *arg)
587 * WARNING: In early boot sc->dev may not be setup yet.
589 sc = (sc_softc_t *)arg;
590 /* assert(thiskbd == sc->kbd) */
595 case KBDIO_UNLOADING:
598 kbd_release(thiskbd, (void *)&sc->keyboard);
605 * Loop while there is still input to get from the keyboard.
606 * I don't think this is nessesary, and it doesn't fix
607 * the Xaccel-2.1 keyboard hang, but it can't hurt. XXX
609 while ((c = scgetc(sc, SCGETC_NONBLOCK)) != NOKEY) {
610 cur_tty = VIRTUAL_TTY(sc, sc->cur_scp->index);
611 if (!ISTTYOPEN(cur_tty)) {
612 cur_tty = sc_console_tty;
613 if (!ISTTYOPEN(cur_tty))
617 if ((*sc->cur_scp->tsw->te_input)(sc->cur_scp, c, cur_tty))
620 switch (KEYFLAGS(c)) {
621 case 0x0000: /* normal key */
622 (*linesw[cur_tty->t_line].l_rint)(KEYCHAR(c), cur_tty);
624 case FKEY: /* function key, return string */
625 cp = kbd_get_fkeystr(thiskbd, KEYCHAR(c), &len);
628 (*linesw[cur_tty->t_line].l_rint)(*cp++, cur_tty);
631 case MKEY: /* meta is active, prepend ESC */
632 (*linesw[cur_tty->t_line].l_rint)(0x1b, cur_tty);
633 (*linesw[cur_tty->t_line].l_rint)(KEYCHAR(c), cur_tty);
635 case BKEY: /* backtab fixed sequence (esc [ Z) */
636 (*linesw[cur_tty->t_line].l_rint)(0x1b, cur_tty);
637 (*linesw[cur_tty->t_line].l_rint)('[', cur_tty);
638 (*linesw[cur_tty->t_line].l_rint)('Z', cur_tty);
643 sc->cur_scp->status |= MOUSE_HIDDEN;
649 scparam(struct tty *tp, struct termios *t)
651 tp->t_ispeed = t->c_ispeed;
652 tp->t_ospeed = t->c_ospeed;
653 tp->t_cflag = t->c_cflag;
658 scioctl(struct dev_ioctl_args *ap)
660 cdev_t dev = ap->a_head.a_dev;
661 u_long cmd = ap->a_cmd;
662 caddr_t data = ap->a_data;
663 int flag = ap->a_fflag;
672 error = sc_vid_ioctl(tp, cmd, data, flag);
673 if (error != ENOIOCTL)
676 #ifndef SC_NO_HISTORY
677 error = sc_hist_ioctl(tp, cmd, data, flag);
678 if (error != ENOIOCTL)
682 #ifndef SC_NO_SYSMOUSE
683 error = sc_mouse_ioctl(tp, cmd, data, flag);
684 if (error != ENOIOCTL)
688 scp = SC_STAT(tp->t_dev);
689 /* assert(scp != NULL) */
690 /* scp is sc_console, if SC_VTY(dev) == SC_CONSOLECTL. */
694 error = (*scp->tsw->te_ioctl)(scp, tp, cmd, data, flag);
695 if (error != ENOIOCTL)
699 switch (cmd) { /* process console hardware related ioctl's */
701 case GIO_ATTR: /* get current attributes */
702 /* this ioctl is not processed here, but in the terminal emulator */
705 case GIO_COLOR: /* is this a color console ? */
706 *(int *)data = (sc->adp->va_flags & V_ADP_COLOR) ? 1 : 0;
709 case CONS_BLANKTIME: /* set screen saver timeout (0 = no saver) */
710 if (*(int *)data < 0 || *(int *)data > MAX_BLANKTIME)
713 scrn_blank_time = *(int *)data;
714 run_scrn_saver = (scrn_blank_time != 0);
718 case CONS_CURSORTYPE: /* set cursor type blink/noblink */
720 if (!ISGRAPHSC(sc->cur_scp))
721 sc_remove_cursor_image(sc->cur_scp);
722 if ((*(int*)data) & 0x01)
723 sc->flags |= SC_BLINK_CURSOR;
725 sc->flags &= ~SC_BLINK_CURSOR;
726 if ((*(int*)data) & 0x02) {
727 sc->flags |= SC_CHAR_CURSOR;
729 sc->flags &= ~SC_CHAR_CURSOR;
731 * The cursor shape is global property; all virtual consoles
732 * are affected. Update the cursor in the current console...
734 if (!ISGRAPHSC(sc->cur_scp)) {
735 sc_set_cursor_image(sc->cur_scp);
736 sc_draw_cursor_image(sc->cur_scp);
741 case CONS_BELLTYPE: /* set bell type sound/visual */
742 if ((*(int *)data) & 0x01)
743 sc->flags |= SC_VISUAL_BELL;
745 sc->flags &= ~SC_VISUAL_BELL;
746 if ((*(int *)data) & 0x02)
747 sc->flags |= SC_QUIET_BELL;
749 sc->flags &= ~SC_QUIET_BELL;
752 case CONS_GETINFO: /* get current (virtual) console info */
754 vid_info_t *ptr = (vid_info_t*)data;
755 if (ptr->size == sizeof(struct vid_info)) {
756 ptr->m_num = sc->cur_scp->index;
757 ptr->font_size = scp->font_size;
758 ptr->mv_col = scp->xpos;
759 ptr->mv_row = scp->ypos;
760 ptr->mv_csz = scp->xsize;
761 ptr->mv_rsz = scp->ysize;
763 * The following fields are filled by the terminal emulator. XXX
770 ptr->mv_grfc.fore = 0; /* not supported */
771 ptr->mv_grfc.back = 0; /* not supported */
772 ptr->mv_ovscan = scp->border;
773 if (scp == sc->cur_scp)
775 ptr->mk_keylock = scp->status & LOCK_MASK;
781 case CONS_GETVERS: /* get version number */
782 *(int*)data = 0x200; /* version 2.0 */
785 case CONS_IDLE: /* see if the screen has been idle */
787 * When the screen is in the GRAPHICS_MODE or UNKNOWN_MODE,
788 * the user process may have been writing something on the
789 * screen and syscons is not aware of it. Declare the screen
790 * is NOT idle if it is in one of these modes. But there is
791 * an exception to it; if a screen saver is running in the
792 * graphics mode in the current screen, we should say that the
793 * screen has been idle.
795 *(int *)data = (sc->flags & SC_SCRN_IDLE)
796 && (!ISGRAPHSC(sc->cur_scp)
797 || (sc->cur_scp->status & SAVER_RUNNING));
800 case CONS_SAVERMODE: /* set saver mode */
801 switch(*(int *)data) {
804 /* if a LKM screen saver is running, stop it first. */
805 scsplash_stick(FALSE);
806 saver_mode = *(int *)data;
809 if ((error = wait_scrn_saver_stop(NULL))) {
814 run_scrn_saver = TRUE;
815 if (saver_mode == CONS_USR_SAVER)
816 scp->status |= SAVER_RUNNING;
818 scp->status &= ~SAVER_RUNNING;
819 scsplash_stick(TRUE);
824 if ((saver_mode == CONS_USR_SAVER) && (scp->status & SAVER_RUNNING))
825 scp->status &= ~SAVER_RUNNING;
826 saver_mode = *(int *)data;
834 case CONS_SAVERSTART: /* immediately start/stop the screen saver */
836 * Note that this ioctl does not guarantee the screen saver
837 * actually starts or stops. It merely attempts to do so...
840 run_scrn_saver = (*(int *)data != 0);
842 sc->scrn_time_stamp -= scrn_blank_time;
846 case CONS_SCRSHOT: /* get a screen shot */
848 scrshot_t *ptr = (scrshot_t*)data;
850 if (ISGRAPHSC(scp)) {
854 if (scp->xsize != ptr->xsize || scp->ysize != ptr->ysize) {
858 copyout ((void*)scp->vtb.vtb_buffer, ptr->buf,
859 ptr->xsize * ptr->ysize * sizeof(uint16_t));
864 case VT_SETMODE: /* set screen switcher mode */
866 struct vt_mode *mode;
868 mode = (struct vt_mode *)data;
869 DPRINTF(5, ("sc%d: VT_SETMODE ", sc->unit));
870 if (scp->smode.mode == VT_PROCESS) {
871 if (scp->proc == pfind(scp->pid) && scp->proc != curproc) {
872 DPRINTF(5, ("error EPERM\n"));
877 if (mode->mode == VT_AUTO) {
878 scp->smode.mode = VT_AUTO;
881 DPRINTF(5, ("VT_AUTO, "));
882 if ((scp == sc->cur_scp) && (sc->unit == sc_console_unit))
883 cons_unavail = FALSE;
885 * note: must be called from a critical section because
886 * finish_vt_rel will call do_switch_scr which releases it
889 if (finish_vt_rel(scp, TRUE) == 0)
890 DPRINTF(5, ("reset WAIT_REL, "));
891 if (finish_vt_acq(scp) == 0)
892 DPRINTF(5, ("reset WAIT_ACQ, "));
894 if (!ISSIGVALID(mode->relsig) || !ISSIGVALID(mode->acqsig)
895 || !ISSIGVALID(mode->frsig)) {
897 DPRINTF(5, ("error EINVAL\n"));
900 DPRINTF(5, ("VT_PROCESS %d, ", curproc->p_pid));
901 bcopy(data, &scp->smode, sizeof(struct vt_mode));
903 scp->pid = scp->proc->p_pid;
904 if ((scp == sc->cur_scp) && (sc->unit == sc_console_unit))
912 case VT_GETMODE: /* get screen switcher mode */
913 bcopy(&scp->smode, data, sizeof(struct vt_mode));
916 case VT_RELDISP: /* screen switcher ioctl */
919 * This must be the current vty which is in the VT_PROCESS
922 if ((scp != sc->cur_scp) || (scp->smode.mode != VT_PROCESS)) {
926 /* ...and this process is controlling it. */
927 if (scp->proc != curproc) {
932 switch(*(int *)data) {
933 case VT_FALSE: /* user refuses to release screen, abort */
935 * note: must be called from a critical section because
936 * finish_vt_rel will call do_switch_scr which releases it
939 if ((error = finish_vt_rel(scp, FALSE)) == 0)
940 DPRINTF(5, ("sc%d: VT_FALSE\n", sc->unit));
942 case VT_TRUE: /* user has released screen, go on */
944 * note: must be called from a critical section because
945 * finish_vt_rel will call do_switch_scr which releases it
948 if ((error = finish_vt_rel(scp, TRUE)) == 0)
949 DPRINTF(5, ("sc%d: VT_TRUE\n", sc->unit));
951 case VT_ACKACQ: /* acquire acknowledged, switch completed */
952 if ((error = finish_vt_acq(scp)) == 0)
953 DPRINTF(5, ("sc%d: VT_ACKACQ\n", sc->unit));
961 case VT_OPENQRY: /* return free virtual console */
962 for (i = sc->first_vty; i < sc->first_vty + sc->vtys; i++) {
963 tp = VIRTUAL_TTY(sc, i);
964 if (!ISTTYOPEN(tp)) {
965 *(int *)data = i + 1;
971 case VT_ACTIVATE: /* switch to screen *data */
972 i = (*(int *)data == 0) ? scp->index : (*(int *)data - 1);
974 sc_clean_up(sc->cur_scp);
976 return sc_switch_scr(sc, i);
978 case VT_WAITACTIVE: /* wait for switch to occur */
979 i = (*(int *)data == 0) ? scp->index : (*(int *)data - 1);
980 if ((i < sc->first_vty) || (i >= sc->first_vty + sc->vtys))
983 error = sc_clean_up(sc->cur_scp);
987 scp = SC_STAT(SC_DEV(sc, i));
988 if (scp == scp->sc->cur_scp)
990 error = tsleep((caddr_t)&scp->smode, PCATCH, "waitvt", 0);
991 /* May return ERESTART */
994 case VT_GETACTIVE: /* get active vty # */
995 *(int *)data = sc->cur_scp->index + 1;
998 case VT_GETINDEX: /* get this vty # */
999 *(int *)data = scp->index + 1;
1002 case VT_LOCKSWITCH: /* prevent vty switching */
1003 if ((*(int *)data) & 0x01)
1004 sc->flags |= SC_SCRN_VTYLOCK;
1006 sc->flags &= ~SC_SCRN_VTYLOCK;
1009 case KDENABIO: /* allow io operations */
1010 error = priv_check_cred(ap->a_cred, PRIV_ROOT, 0);
1013 if (securelevel > 0)
1015 #if defined(__i386__)
1016 curthread->td_lwp->lwp_md.md_regs->tf_eflags |= PSL_IOPL;
1017 #elif defined(__x86_64__)
1018 curthread->td_lwp->lwp_md.md_regs->tf_rflags |= PSL_IOPL;
1022 case KDDISABIO: /* disallow io operations (default) */
1023 #if defined(__i386__)
1024 curthread->td_lwp->lwp_md.md_regs->tf_eflags &= ~PSL_IOPL;
1025 #elif defined(__x86_64__)
1026 curthread->td_lwp->lwp_md.md_regs->tf_rflags &= ~PSL_IOPL;
1030 case KDSKBSTATE: /* set keyboard state (locks) */
1031 if (*(int *)data & ~LOCK_MASK)
1033 scp->status &= ~LOCK_MASK;
1034 scp->status |= *(int *)data;
1035 if (scp == sc->cur_scp)
1036 update_kbd_state(scp, scp->status, LOCK_MASK);
1039 case KDGKBSTATE: /* get keyboard state (locks) */
1040 if (scp == sc->cur_scp)
1041 save_kbd_state(scp);
1042 *(int *)data = scp->status & LOCK_MASK;
1045 case KDGETREPEAT: /* get keyboard repeat & delay rates */
1046 case KDSETREPEAT: /* set keyboard repeat & delay rates (new) */
1047 error = kbd_ioctl(sc->kbd, cmd, data);
1048 if (error == ENOIOCTL)
1052 case KDSETRAD: /* set keyboard repeat & delay rates (old) */
1053 if (*(int *)data & ~0x7f)
1055 error = kbd_ioctl(sc->kbd, cmd, data);
1056 if (error == ENOIOCTL)
1060 case KDSKBMODE: /* set keyboard mode */
1061 switch (*(int *)data) {
1062 case K_XLATE: /* switch to XLT ascii mode */
1063 case K_RAW: /* switch to RAW scancode mode */
1064 case K_CODE: /* switch to CODE mode */
1065 scp->kbd_mode = *(int *)data;
1066 if (scp == sc->cur_scp)
1067 kbd_ioctl(sc->kbd, cmd, data);
1074 case KDGKBMODE: /* get keyboard mode */
1075 *(int *)data = scp->kbd_mode;
1079 error = kbd_ioctl(sc->kbd, cmd, data);
1080 if (error == ENOIOCTL)
1084 case KDMKTONE: /* sound the bell */
1086 sc_bell(scp, (*(int*)data)&0xffff,
1087 (((*(int*)data)>>16)&0xffff)*hz/1000);
1089 sc_bell(scp, scp->bell_pitch, scp->bell_duration);
1092 case KIOCSOUND: /* make tone (*data) hz */
1093 if (scp == sc->cur_scp) {
1095 return sc_tone(*(int *)data);
1101 case KDGKBTYPE: /* get keyboard type */
1102 error = kbd_ioctl(sc->kbd, cmd, data);
1103 if (error == ENOIOCTL) {
1104 /* always return something? XXX */
1109 case KDSETLED: /* set keyboard LED status */
1110 if (*(int *)data & ~LED_MASK) /* FIXME: LOCK_MASK? */
1112 scp->status &= ~LED_MASK;
1113 scp->status |= *(int *)data;
1114 if (scp == sc->cur_scp)
1115 update_kbd_leds(scp, scp->status);
1118 case KDGETLED: /* get keyboard LED status */
1119 if (scp == sc->cur_scp)
1120 save_kbd_state(scp);
1121 *(int *)data = scp->status & LED_MASK;
1124 case KBADDKBD: /* add/remove keyboard to/from mux */
1126 error = kbd_ioctl(sc->kbd, cmd, data);
1127 if (error == ENOIOCTL)
1131 case CONS_SETKBD: /* set the new keyboard */
1136 newkbd = kbd_get_keyboard(*(int *)data);
1137 if (newkbd == NULL) {
1142 if (sc->kbd != newkbd) {
1143 i = kbd_allocate(newkbd->kb_name, newkbd->kb_unit,
1144 (void *)&sc->keyboard, sckbdevent, sc);
1145 /* i == newkbd->kb_index */
1147 if (sc->kbd != NULL) {
1148 save_kbd_state(sc->cur_scp);
1149 kbd_release(sc->kbd, (void *)&sc->keyboard);
1151 sc->kbd = kbd_get_keyboard(i); /* sc->kbd == newkbd */
1153 kbd_ioctl(sc->kbd, KDSKBMODE,
1154 (caddr_t)&sc->cur_scp->kbd_mode);
1155 update_kbd_state(sc->cur_scp, sc->cur_scp->status,
1158 error = EPERM; /* XXX */
1165 case CONS_RELKBD: /* release the current keyboard */
1168 if (sc->kbd != NULL) {
1169 save_kbd_state(sc->cur_scp);
1170 error = kbd_release(sc->kbd, (void *)&sc->keyboard);
1179 case CONS_GETTERM: /* get the current terminal emulator info */
1183 if (((term_info_t *)data)->ti_index == 0) {
1186 sw = sc_term_match_by_number(((term_info_t *)data)->ti_index);
1189 strncpy(((term_info_t *)data)->ti_name, sw->te_name,
1190 sizeof(((term_info_t *)data)->ti_name));
1191 strncpy(((term_info_t *)data)->ti_desc, sw->te_desc,
1192 sizeof(((term_info_t *)data)->ti_desc));
1193 ((term_info_t *)data)->ti_flags = 0;
1196 ((term_info_t *)data)->ti_name[0] = '\0';
1197 ((term_info_t *)data)->ti_desc[0] = '\0';
1198 ((term_info_t *)data)->ti_flags = 0;
1203 case CONS_SETTERM: /* set the current terminal emulator */
1205 error = sc_init_emulator(scp, ((term_info_t *)data)->ti_name);
1206 /* FIXME: what if scp == sc_console! XXX */
1210 case GIO_SCRNMAP: /* get output translation table */
1211 bcopy(&sc->scr_map, data, sizeof(sc->scr_map));
1214 case PIO_SCRNMAP: /* set output translation table */
1215 bcopy(data, &sc->scr_map, sizeof(sc->scr_map));
1216 for (i=0; i<sizeof(sc->scr_map); i++) {
1217 sc->scr_rmap[sc->scr_map[i]] = i;
1221 case GIO_KEYMAP: /* get keyboard translation table */
1222 case PIO_KEYMAP: /* set keyboard translation table */
1223 case GIO_DEADKEYMAP: /* get accent key translation table */
1224 case PIO_DEADKEYMAP: /* set accent key translation table */
1225 case GETFKEY: /* get function key string */
1226 case SETFKEY: /* set function key string */
1227 error = kbd_ioctl(sc->kbd, cmd, data);
1228 if (error == ENOIOCTL)
1232 #ifndef SC_NO_FONT_LOADING
1234 case PIO_FONT8x8: /* set 8x8 dot font */
1235 if (!ISFONTAVAIL(sc->adp->va_flags))
1237 bcopy(data, sc->font_8, 8*256);
1238 sc->fonts_loaded |= FONT_8;
1241 * Always use the font page #0. XXX
1242 * Don't load if the current font size is not 8x8.
1244 if (ISTEXTSC(sc->cur_scp) && (sc->cur_scp->font_size < 14))
1245 sc_load_font(sc->cur_scp, 0, 8, sc->font_8, 0, 256);
1248 case GIO_FONT8x8: /* get 8x8 dot font */
1249 if (!ISFONTAVAIL(sc->adp->va_flags))
1251 if (sc->fonts_loaded & FONT_8) {
1252 bcopy(sc->font_8, data, 8*256);
1258 case PIO_FONT8x14: /* set 8x14 dot font */
1259 if (!ISFONTAVAIL(sc->adp->va_flags))
1261 bcopy(data, sc->font_14, 14*256);
1262 sc->fonts_loaded |= FONT_14;
1265 * Always use the font page #0. XXX
1266 * Don't load if the current font size is not 8x14.
1268 if (ISTEXTSC(sc->cur_scp)
1269 && (sc->cur_scp->font_size >= 14)
1270 && (sc->cur_scp->font_size < 16))
1271 sc_load_font(sc->cur_scp, 0, 14, sc->font_14, 0, 256);
1274 case GIO_FONT8x14: /* get 8x14 dot font */
1275 if (!ISFONTAVAIL(sc->adp->va_flags))
1277 if (sc->fonts_loaded & FONT_14) {
1278 bcopy(sc->font_14, data, 14*256);
1284 case PIO_FONT8x16: /* set 8x16 dot font */
1285 if (!ISFONTAVAIL(sc->adp->va_flags))
1287 bcopy(data, sc->font_16, 16*256);
1288 sc->fonts_loaded |= FONT_16;
1291 * Always use the font page #0. XXX
1292 * Don't load if the current font size is not 8x16.
1294 if (ISTEXTSC(sc->cur_scp) && (sc->cur_scp->font_size >= 16))
1295 sc_load_font(sc->cur_scp, 0, 16, sc->font_16, 0, 256);
1298 case GIO_FONT8x16: /* get 8x16 dot font */
1299 if (!ISFONTAVAIL(sc->adp->va_flags))
1301 if (sc->fonts_loaded & FONT_16) {
1302 bcopy(sc->font_16, data, 16*256);
1308 #endif /* SC_NO_FONT_LOADING */
1314 error = (*linesw[tp->t_line].l_ioctl)(tp, cmd, data, flag, ap->a_cred);
1315 if (error != ENOIOCTL)
1317 error = ttioctl(tp, cmd, data, flag);
1318 if (error != ENOIOCTL)
1324 scstart(struct tty *tp)
1328 u_char buf[PCBURST];
1329 scr_stat *scp = SC_STAT(tp->t_dev);
1331 if (scp->status & SLKED ||
1332 (scp == scp->sc->cur_scp && scp->sc->blink_in_progress))
1335 if (!(tp->t_state & (TS_TIMEOUT | TS_BUSY | TS_TTSTOP))) {
1336 tp->t_state |= TS_BUSY;
1339 len = q_to_b(rbp, buf, PCBURST);
1341 sc_puts(scp, buf, len);
1344 tp->t_state &= ~TS_BUSY;
1351 sccnprobe(struct consdev *cp)
1356 cp->cn_pri = sc_get_cons_priority(&unit, &flags);
1358 /* a video card is always required */
1359 if (!scvidprobe(unit, flags, TRUE))
1360 cp->cn_pri = CN_DEAD;
1362 /* syscons will become console even when there is no keyboard */
1363 sckbdprobe(unit, flags, TRUE);
1365 if (cp->cn_pri == CN_DEAD)
1368 /* initialize required fields */
1369 cp->cn_probegood = 1;
1373 sccninit(struct consdev *cp)
1378 sc_get_cons_priority(&unit, &flags);
1379 scinit(unit, flags | SC_KERNEL_CONSOLE);
1380 sc_console_unit = unit;
1381 sc_console = sc_get_softc(unit, SC_KERNEL_CONSOLE)->console_scp;
1385 sccninit_fini(struct consdev *cp)
1387 if (cctl_dev == NULL)
1388 kprintf("sccninit_fini: WARNING: cctl_dev is NULL!\n");
1389 cp->cn_dev = cctl_dev;
1393 sccnterm(struct consdev *cp)
1395 /* we are not the kernel console any more, release everything */
1397 if (sc_console_unit < 0)
1398 return; /* shouldn't happen */
1401 sc_clear_screen(sc_console);
1402 sccnupdate(sc_console);
1404 scterm(sc_console_unit, SC_KERNEL_CONSOLE);
1405 sc_console_unit = -1;
1410 sccnputc(void *private, int c)
1413 scr_stat *scp = sc_console;
1415 #ifndef SC_NO_HISTORY
1417 #endif /* !SC_NO_HISTORY */
1419 /* assert(sc_console != NULL) */
1421 #ifndef SC_NO_HISTORY
1422 if (scp == scp->sc->cur_scp && scp->status & SLKED) {
1423 scp->status &= ~SLKED;
1424 update_kbd_state(scp, scp->status, SLKED);
1425 if (scp->status & BUFFER_SAVED) {
1426 if (!sc_hist_restore(scp))
1427 sc_remove_cutmarking(scp);
1428 scp->status &= ~BUFFER_SAVED;
1429 scp->status |= CURSOR_ENABLED;
1430 sc_draw_cursor_image(scp);
1432 tp = VIRTUAL_TTY(scp->sc, scp->index);
1436 #endif /* !SC_NO_HISTORY */
1439 if (kernel_console_ts != NULL)
1440 scp->ts = kernel_console_ts;
1442 sc_puts(scp, buf, 1);
1451 sccngetc(void *private)
1453 return sccngetch(0);
1457 sccncheckc(void *private)
1459 return sccngetch(SCGETC_NONBLOCK);
1463 sccndbctl(void *private, int on)
1465 /* assert(sc_console_unit >= 0) */
1466 /* try to switch to the kernel console screen */
1467 if (on && debugger == 0) {
1469 * TRY to make sure the screen saver is stopped,
1470 * and the screen is updated before switching to
1475 && sc_console->sc->cur_scp->smode.mode == VT_AUTO
1476 && sc_console->smode.mode == VT_AUTO) {
1477 sc_console->sc->cur_scp->status |= MOUSE_HIDDEN;
1478 sc_switch_scr(sc_console->sc, sc_console->index);
1488 sccngetch(int flags)
1490 static struct fkeytab fkey;
1498 /* assert(sc_console != NULL) */
1501 * Stop the screen saver and update the screen if necessary.
1502 * What if we have been running in the screen saver code... XXX
1504 sc_touch_scrn_saver();
1505 scp = sc_console->sc->cur_scp; /* XXX */
1508 if (fkeycp < fkey.len) {
1510 return fkey.str[fkeycp++];
1513 if (scp->sc->kbd == NULL) {
1519 * Make sure the keyboard is accessible even when the kbd device
1520 * driver is disabled.
1522 kbd_enable(scp->sc->kbd);
1524 /* we shall always use the keyboard in the XLATE mode here */
1525 cur_mode = scp->kbd_mode;
1526 scp->kbd_mode = K_XLATE;
1527 kbd_ioctl(scp->sc->kbd, KDSKBMODE, (caddr_t)&scp->kbd_mode);
1529 kbd_poll(scp->sc->kbd, TRUE);
1530 c = scgetc(scp->sc, SCGETC_CN | flags);
1531 kbd_poll(scp->sc->kbd, FALSE);
1533 scp->kbd_mode = cur_mode;
1534 kbd_ioctl(scp->sc->kbd, KDSKBMODE, (caddr_t)&scp->kbd_mode);
1535 kbd_disable(scp->sc->kbd);
1538 switch (KEYFLAGS(c)) {
1539 case 0: /* normal char */
1541 case FKEY: /* function key */
1542 p = kbd_get_fkeystr(scp->sc->kbd, KEYCHAR(c), (size_t *)&fkeycp);
1544 if ((p != NULL) && (fkey.len > 0)) {
1545 bcopy(p, fkey.str, fkey.len);
1559 sccnupdate(scr_stat *scp)
1561 /* this is a cut-down version of scrn_timer()... */
1563 if (scp->sc->font_loading_in_progress || scp->sc->videoio_in_progress)
1566 if (debugger > 0 || panicstr || shutdown_in_progress) {
1567 sc_touch_scrn_saver();
1568 } else if (scp != scp->sc->cur_scp) {
1572 if (!run_scrn_saver)
1573 scp->sc->flags &= ~SC_SCRN_IDLE;
1575 if ((saver_mode != CONS_LKM_SAVER) || !(scp->sc->flags & SC_SCRN_IDLE))
1576 if (scp->sc->flags & SC_SCRN_BLANKED)
1577 stop_scrn_saver(scp->sc, current_saver);
1578 #endif /* NSPLASH */
1580 if (scp != scp->sc->cur_scp || scp->sc->blink_in_progress
1581 || scp->sc->switch_in_progress)
1584 * FIXME: unlike scrn_timer(), we call scrn_update() from here even
1585 * when write_in_progress is non-zero. XXX
1588 if (!ISGRAPHSC(scp) && !(scp->sc->flags & SC_SCRN_BLANKED))
1589 scrn_update(scp, TRUE);
1593 scrn_timer(void *arg)
1595 static int kbd_interval = 0;
1601 again = (arg != NULL);
1603 sc = (sc_softc_t *)arg;
1604 else if (sc_console != NULL)
1605 sc = sc_console->sc;
1609 /* don't do anything when we are performing some I/O operations */
1610 if (sc->font_loading_in_progress || sc->videoio_in_progress) {
1612 callout_reset(&sc->scrn_timer_ch, hz / 10, scrn_timer, sc);
1617 if ((sc->kbd == NULL) && (sc->config & SC_AUTODETECT_KBD)) {
1618 /* try to allocate a keyboard automatically */
1619 if (++kbd_interval >= 25) {
1620 sc->keyboard = sc_allocate_keyboard(sc, -1);
1621 if (sc->keyboard >= 0) {
1622 sc->kbd = kbd_get_keyboard(sc->keyboard);
1623 kbd_ioctl(sc->kbd, KDSKBMODE,
1624 (caddr_t)&sc->cur_scp->kbd_mode);
1625 update_kbd_state(sc->cur_scp, sc->cur_scp->status,
1632 /* should we stop the screen saver? */
1633 getmicrouptime(&tv);
1634 if (debugger > 0 || panicstr || shutdown_in_progress)
1635 sc_touch_scrn_saver();
1636 if (run_scrn_saver) {
1637 if (tv.tv_sec > sc->scrn_time_stamp + scrn_blank_time)
1638 sc->flags |= SC_SCRN_IDLE;
1640 sc->flags &= ~SC_SCRN_IDLE;
1642 sc->scrn_time_stamp = tv.tv_sec;
1643 sc->flags &= ~SC_SCRN_IDLE;
1644 if (scrn_blank_time > 0)
1645 run_scrn_saver = TRUE;
1648 if ((saver_mode != CONS_LKM_SAVER) || !(sc->flags & SC_SCRN_IDLE))
1649 if (sc->flags & SC_SCRN_BLANKED)
1650 stop_scrn_saver(sc, current_saver);
1651 #endif /* NSPLASH */
1653 /* should we just return ? */
1654 if (sc->blink_in_progress || sc->switch_in_progress
1655 || sc->write_in_progress) {
1657 callout_reset(&sc->scrn_timer_ch, hz / 10, scrn_timer, sc);
1662 /* Update the screen */
1663 scp = sc->cur_scp; /* cur_scp may have changed... */
1664 if (!ISGRAPHSC(scp) && !(sc->flags & SC_SCRN_BLANKED))
1665 scrn_update(scp, TRUE);
1668 /* should we activate the screen saver? */
1669 if ((saver_mode == CONS_LKM_SAVER) && (sc->flags & SC_SCRN_IDLE))
1670 if (!ISGRAPHSC(scp) || (sc->flags & SC_SCRN_BLANKED))
1671 (*current_saver)(sc, TRUE);
1672 #endif /* NSPLASH */
1675 callout_reset(&sc->scrn_timer_ch, hz / 25, scrn_timer, sc);
1680 and_region(int *s1, int *e1, int s2, int e2)
1682 if (*e1 < s2 || e2 < *s1)
1684 *s1 = imax(*s1, s2);
1685 *e1 = imin(*e1, e2);
1690 scrn_update(scr_stat *scp, int show_cursor)
1697 /* assert(scp == scp->sc->cur_scp) */
1699 ++scp->sc->videoio_in_progress;
1701 #ifndef SC_NO_CUTPASTE
1702 /* remove the previous mouse pointer image if necessary */
1703 if (scp->status & MOUSE_VISIBLE) {
1705 e = scp->mouse_pos + scp->xsize + 1;
1706 if ((scp->status & (MOUSE_MOVED | MOUSE_HIDDEN))
1707 || and_region(&s, &e, scp->start, scp->end)
1708 || ((scp->status & CURSOR_ENABLED) &&
1709 (scp->cursor_pos != scp->cursor_oldpos) &&
1710 (and_region(&s, &e, scp->cursor_pos, scp->cursor_pos)
1711 || and_region(&s, &e, scp->cursor_oldpos, scp->cursor_oldpos)))) {
1712 sc_remove_mouse_image(scp);
1713 if (scp->end >= scp->xsize*scp->ysize)
1714 scp->end = scp->xsize*scp->ysize - 1;
1717 #endif /* !SC_NO_CUTPASTE */
1721 if (scp->end >= scp->xsize*scp->ysize) {
1722 kprintf("scrn_update(): scp->end %d > size_of_screen!!\n", scp->end);
1723 scp->end = scp->xsize*scp->ysize - 1;
1725 if (scp->start < 0) {
1726 kprintf("scrn_update(): scp->start %d < 0\n", scp->start);
1731 /* update screen image */
1732 if (scp->start <= scp->end) {
1733 if (scp->mouse_cut_end >= 0) {
1734 /* there is a marked region for cut & paste */
1735 if (scp->mouse_cut_start <= scp->mouse_cut_end) {
1736 start = scp->mouse_cut_start;
1737 end = scp->mouse_cut_end;
1739 start = scp->mouse_cut_end;
1740 end = scp->mouse_cut_start - 1;
1744 /* does the cut-mark region overlap with the update region? */
1745 if (and_region(&s, &e, scp->start, scp->end)) {
1746 (*scp->rndr->draw)(scp, s, e - s + 1, TRUE);
1749 if (and_region(&s, &e, scp->start, scp->end))
1750 (*scp->rndr->draw)(scp, s, e - s + 1, FALSE);
1752 e = scp->xsize*scp->ysize - 1;
1753 if (and_region(&s, &e, scp->start, scp->end))
1754 (*scp->rndr->draw)(scp, s, e - s + 1, FALSE);
1756 (*scp->rndr->draw)(scp, scp->start,
1757 scp->end - scp->start + 1, FALSE);
1760 (*scp->rndr->draw)(scp, scp->start,
1761 scp->end - scp->start + 1, FALSE);
1765 /* we are not to show the cursor and the mouse pointer... */
1768 scp->start = scp->xsize*scp->ysize - 1;
1769 --scp->sc->videoio_in_progress;
1773 /* update cursor image */
1774 if (scp->status & CURSOR_ENABLED) {
1777 /* did cursor move since last time ? */
1778 if (scp->cursor_pos != scp->cursor_oldpos) {
1779 /* do we need to remove old cursor image ? */
1780 if (!and_region(&s, &e, scp->cursor_oldpos, scp->cursor_oldpos))
1781 sc_remove_cursor_image(scp);
1782 sc_draw_cursor_image(scp);
1784 if (and_region(&s, &e, scp->cursor_pos, scp->cursor_pos))
1785 /* cursor didn't move, but has been overwritten */
1786 sc_draw_cursor_image(scp);
1787 else if (scp->sc->flags & SC_BLINK_CURSOR)
1788 /* if it's a blinking cursor, update it */
1789 (*scp->rndr->blink_cursor)(scp, scp->cursor_pos,
1790 sc_inside_cutmark(scp,
1795 #ifndef SC_NO_CUTPASTE
1796 /* update "pseudo" mouse pointer image */
1797 if (scp->sc->flags & SC_MOUSE_ENABLED) {
1798 if (!(scp->status & (MOUSE_VISIBLE | MOUSE_HIDDEN))) {
1799 scp->status &= ~MOUSE_MOVED;
1800 sc_draw_mouse_image(scp);
1803 #endif /* SC_NO_CUTPASTE */
1806 scp->start = scp->xsize*scp->ysize - 1;
1808 --scp->sc->videoio_in_progress;
1813 scsplash_callback(int event, void *arg)
1818 sc = (sc_softc_t *)arg;
1822 if (add_scrn_saver(scsplash_saver) == 0) {
1823 sc->flags &= ~SC_SAVER_FAILED;
1824 run_scrn_saver = TRUE;
1825 if (cold && !(boothowto & (RB_VERBOSE | RB_CONFIG))) {
1826 scsplash_stick(TRUE);
1827 (*current_saver)(sc, TRUE);
1833 if (current_saver == scsplash_saver) {
1834 scsplash_stick(FALSE);
1835 error = remove_scrn_saver(scsplash_saver);
1847 scsplash_saver(sc_softc_t *sc, int show)
1849 static int busy = FALSE;
1858 if (!(sc->flags & SC_SAVER_FAILED)) {
1859 if (!(sc->flags & SC_SCRN_BLANKED))
1860 set_scrn_saver_mode(scp, -1, NULL, 0);
1861 switch (splash(sc->adp, TRUE)) {
1862 case 0: /* succeeded */
1864 case EAGAIN: /* try later */
1865 restore_scrn_saver_mode(scp, FALSE);
1866 sc_touch_scrn_saver(); /* XXX */
1869 sc->flags |= SC_SAVER_FAILED;
1870 scsplash_stick(FALSE);
1871 restore_scrn_saver_mode(scp, TRUE);
1872 kprintf("scsplash_saver(): failed to put up the image\n");
1876 } else if (!sticky_splash) {
1877 if ((sc->flags & SC_SCRN_BLANKED) && (splash(sc->adp, FALSE) == 0))
1878 restore_scrn_saver_mode(scp, TRUE);
1884 add_scrn_saver(void (*this_saver)(sc_softc_t *, int))
1889 if (current_saver != none_saver) {
1890 error = remove_scrn_saver(current_saver);
1895 if (current_saver != none_saver)
1898 run_scrn_saver = FALSE;
1899 saver_mode = CONS_LKM_SAVER;
1900 current_saver = this_saver;
1905 remove_scrn_saver(void (*this_saver)(sc_softc_t *, int))
1907 if (current_saver != this_saver)
1912 * In order to prevent `current_saver' from being called by
1913 * the timeout routine `scrn_timer()' while we manipulate
1914 * the saver list, we shall set `current_saver' to `none_saver'
1915 * before stopping the current saver, rather than blocking by `splXX()'.
1917 current_saver = none_saver;
1919 stop_scrn_saver(this_saver);
1922 /* unblank all blanked screens */
1923 wait_scrn_saver_stop(NULL);
1927 current_saver = none_saver;
1932 set_scrn_saver_mode(scr_stat *scp, int mode, u_char *pal, int border)
1935 /* assert(scp == scp->sc->cur_scp) */
1937 if (!ISGRAPHSC(scp))
1938 sc_remove_cursor_image(scp);
1939 scp->splash_save_mode = scp->mode;
1940 scp->splash_save_status = scp->status & (GRAPHICS_MODE | PIXEL_MODE);
1941 scp->status &= ~(GRAPHICS_MODE | PIXEL_MODE);
1942 scp->status |= (UNKNOWN_MODE | SAVER_RUNNING);
1943 scp->sc->flags |= SC_SCRN_BLANKED;
1949 if (set_mode(scp) == 0) {
1950 if (scp->sc->adp->va_info.vi_flags & V_INFO_GRAPHICS)
1951 scp->status |= GRAPHICS_MODE;
1952 #ifndef SC_NO_PALETTE_LOADING
1954 load_palette(scp->sc->adp, pal);
1956 sc_set_border(scp, border);
1960 scp->mode = scp->splash_save_mode;
1961 scp->status &= ~(UNKNOWN_MODE | SAVER_RUNNING);
1962 scp->status |= scp->splash_save_status;
1969 restore_scrn_saver_mode(scr_stat *scp, int changemode)
1974 /* assert(scp == scp->sc->cur_scp) */
1977 status = scp->status;
1978 scp->mode = scp->splash_save_mode;
1979 scp->status &= ~(UNKNOWN_MODE | SAVER_RUNNING);
1980 scp->status |= scp->splash_save_status;
1981 scp->sc->flags &= ~SC_SCRN_BLANKED;
1983 if (!ISGRAPHSC(scp))
1984 sc_draw_cursor_image(scp);
1989 if (set_mode(scp) == 0) {
1990 #ifndef SC_NO_PALETTE_LOADING
1991 load_palette(scp->sc->adp, scp->sc->palette);
1998 scp->status = status;
2005 stop_scrn_saver(sc_softc_t *sc, void (*saver)(sc_softc_t *, int))
2007 (*saver)(sc, FALSE);
2008 run_scrn_saver = FALSE;
2009 /* the screen saver may have chosen not to stop after all... */
2010 if (sc->flags & SC_SCRN_BLANKED)
2013 mark_all(sc->cur_scp);
2014 if (sc->delayed_next_scr)
2015 sc_switch_scr(sc, sc->delayed_next_scr - 1);
2016 wakeup((caddr_t)&scrn_blanked);
2020 wait_scrn_saver_stop(sc_softc_t *sc)
2024 while (scrn_blanked > 0) {
2025 run_scrn_saver = FALSE;
2026 if (sc && !(sc->flags & SC_SCRN_BLANKED)) {
2030 error = tsleep((caddr_t)&scrn_blanked, PCATCH, "scrsav", 0);
2031 /* May return ERESTART */
2035 run_scrn_saver = FALSE;
2038 #endif /* NSPLASH */
2041 sc_touch_scrn_saver(void)
2043 scsplash_stick(FALSE);
2044 run_scrn_saver = FALSE;
2048 sc_switch_scr(sc_softc_t *sc, u_int next_scr)
2053 DPRINTF(5, ("sc0: sc_switch_scr() %d ", next_scr + 1));
2055 /* prevent switch if previously requested */
2056 if (sc->flags & SC_SCRN_VTYLOCK) {
2057 sc_bell(sc->cur_scp, sc->cur_scp->bell_pitch,
2058 sc->cur_scp->bell_duration);
2062 /* delay switch if the screen is blanked or being updated */
2063 if ((sc->flags & SC_SCRN_BLANKED) || sc->write_in_progress
2064 || sc->blink_in_progress || sc->videoio_in_progress) {
2065 sc->delayed_next_scr = next_scr + 1;
2066 sc_touch_scrn_saver();
2067 DPRINTF(5, ("switch delayed\n"));
2072 cur_scp = sc->cur_scp;
2074 /* we are in the middle of the vty switching process... */
2075 if (sc->switch_in_progress
2076 && (cur_scp->smode.mode == VT_PROCESS)
2078 if (cur_scp->proc != pfind(cur_scp->pid)) {
2080 * The controlling process has died!!. Do some clean up.
2081 * NOTE:`cur_scp->proc' and `cur_scp->smode.mode'
2082 * are not reset here yet; they will be cleared later.
2084 DPRINTF(5, ("cur_scp controlling process %d died, ",
2086 if (cur_scp->status & SWITCH_WAIT_REL) {
2088 * Force the previous switch to finish, but return now
2091 * note: must be called from a critical section because
2092 * finish_vt_rel will call do_switch_scr which releases it
2095 DPRINTF(5, ("reset WAIT_REL, "));
2096 finish_vt_rel(cur_scp, TRUE);
2098 DPRINTF(5, ("finishing previous switch\n"));
2100 } else if (cur_scp->status & SWITCH_WAIT_ACQ) {
2101 /* let's assume screen switch has been completed. */
2102 DPRINTF(5, ("reset WAIT_ACQ, "));
2103 finish_vt_acq(cur_scp);
2106 * We are in between screen release and acquisition, and
2107 * reached here via scgetc() or scrn_timer() which has
2108 * interrupted exchange_scr(). Don't do anything stupid.
2110 DPRINTF(5, ("waiting nothing, "));
2114 * The controlling process is alive, but not responding...
2115 * It is either buggy or it may be just taking time.
2116 * The following code is a gross kludge to cope with this
2117 * problem for which there is no clean solution. XXX
2119 if (cur_scp->status & SWITCH_WAIT_REL) {
2120 switch (sc->switch_in_progress++) {
2124 DPRINTF(5, ("sending relsig again, "));
2125 signal_vt_rel(cur_scp);
2132 * Act as if the controlling program returned
2135 * note: must be called from a critical section because
2136 * finish_vt_rel will call do_switch_scr which releases it
2139 DPRINTF(5, ("force reset WAIT_REL, "));
2140 finish_vt_rel(cur_scp, FALSE);
2142 DPRINTF(5, ("act as if VT_FALSE was seen\n"));
2145 } else if (cur_scp->status & SWITCH_WAIT_ACQ) {
2146 switch (sc->switch_in_progress++) {
2150 DPRINTF(5, ("sending acqsig again, "));
2151 signal_vt_acq(cur_scp);
2157 /* clear the flag and finish the previous switch */
2158 DPRINTF(5, ("force reset WAIT_ACQ, "));
2159 finish_vt_acq(cur_scp);
2167 * Return error if an invalid argument is given, or vty switch
2168 * is still in progress.
2170 if ((next_scr < sc->first_vty) || (next_scr >= sc->first_vty + sc->vtys)
2171 || sc->switch_in_progress) {
2173 sc_bell(cur_scp, bios_value.bell_pitch, BELL_DURATION);
2174 DPRINTF(5, ("error 1\n"));
2179 * Don't allow switching away from the graphics mode vty
2180 * if the switch mode is VT_AUTO, unless the next vty is the same
2181 * as the current or the current vty has been closed (but showing).
2183 tp = VIRTUAL_TTY(sc, cur_scp->index);
2184 if ((cur_scp->index != next_scr)
2186 && (cur_scp->smode.mode == VT_AUTO)
2187 && ISGRAPHSC(cur_scp)) {
2189 sc_bell(cur_scp, bios_value.bell_pitch, BELL_DURATION);
2190 DPRINTF(5, ("error, graphics mode\n"));
2195 * Is the wanted vty open? Don't allow switching to a closed vty.
2196 * If we are in DDB, don't switch to a vty in the VT_PROCESS mode.
2197 * Note that we always allow the user to switch to the kernel
2198 * console even if it is closed.
2200 if ((sc_console == NULL) || (next_scr != sc_console->index)) {
2201 tp = VIRTUAL_TTY(sc, next_scr);
2202 if (!ISTTYOPEN(tp)) {
2204 sc_bell(cur_scp, bios_value.bell_pitch, BELL_DURATION);
2205 DPRINTF(5, ("error 2, requested vty isn't open!\n"));
2208 if ((debugger > 0) && (SC_STAT(tp->t_dev)->smode.mode == VT_PROCESS)) {
2210 DPRINTF(5, ("error 3, requested vty is in the VT_PROCESS mode\n"));
2215 /* this is the start of vty switching process... */
2216 ++sc->switch_in_progress;
2217 sc->delayed_next_scr = 0;
2218 sc->old_scp = cur_scp;
2219 sc->new_scp = SC_STAT(SC_DEV(sc, next_scr));
2220 if (sc->new_scp == sc->old_scp) {
2221 sc->switch_in_progress = 0;
2222 wakeup((caddr_t)&sc->new_scp->smode);
2224 DPRINTF(5, ("switch done (new == old)\n"));
2228 /* has controlling process died? */
2229 vt_proc_alive(sc->old_scp);
2230 vt_proc_alive(sc->new_scp);
2232 /* wait for the controlling process to release the screen, if necessary */
2233 if (signal_vt_rel(sc->old_scp)) {
2238 /* go set up the new vty screen */
2243 /* wake up processes waiting for this vty */
2244 wakeup((caddr_t)&sc->cur_scp->smode);
2246 /* wait for the controlling process to acknowledge, if necessary */
2247 if (signal_vt_acq(sc->cur_scp)) {
2252 sc->switch_in_progress = 0;
2253 if (sc->unit == sc_console_unit)
2254 cons_unavail = FALSE;
2256 DPRINTF(5, ("switch done\n"));
2262 * NOTE: must be called from a critical section because do_switch_scr
2263 * will release it temporarily.
2266 do_switch_scr(sc_softc_t *sc)
2268 vt_proc_alive(sc->new_scp);
2273 /* sc->cur_scp == sc->new_scp */
2274 wakeup((caddr_t)&sc->cur_scp->smode);
2276 /* wait for the controlling process to acknowledge, if necessary */
2277 if (!signal_vt_acq(sc->cur_scp)) {
2278 sc->switch_in_progress = 0;
2279 if (sc->unit == sc_console_unit)
2280 cons_unavail = FALSE;
2285 vt_proc_alive(scr_stat *scp)
2288 if (scp->proc == pfind(scp->pid))
2291 scp->smode.mode = VT_AUTO;
2292 DPRINTF(5, ("vt controlling process %d died\n", scp->pid));
2298 signal_vt_rel(scr_stat *scp)
2300 if (scp->smode.mode != VT_PROCESS)
2302 scp->status |= SWITCH_WAIT_REL;
2303 ksignal(scp->proc, scp->smode.relsig);
2304 DPRINTF(5, ("sending relsig to %d\n", scp->pid));
2309 signal_vt_acq(scr_stat *scp)
2311 if (scp->smode.mode != VT_PROCESS)
2313 if (scp->sc->unit == sc_console_unit)
2314 cons_unavail = TRUE;
2315 scp->status |= SWITCH_WAIT_ACQ;
2316 ksignal(scp->proc, scp->smode.acqsig);
2317 DPRINTF(5, ("sending acqsig to %d\n", scp->pid));
2322 * NOTE: must be called from a critical section because do_switch_scr
2323 * will release it temporarily.
2326 finish_vt_rel(scr_stat *scp, int release)
2328 if (scp == scp->sc->old_scp && scp->status & SWITCH_WAIT_REL) {
2329 scp->status &= ~SWITCH_WAIT_REL;
2331 do_switch_scr(scp->sc);
2333 scp->sc->switch_in_progress = 0;
2340 finish_vt_acq(scr_stat *scp)
2342 if (scp == scp->sc->new_scp && scp->status & SWITCH_WAIT_ACQ) {
2343 scp->status &= ~SWITCH_WAIT_ACQ;
2344 scp->sc->switch_in_progress = 0;
2351 exchange_scr(sc_softc_t *sc)
2355 /* save the current state of video and keyboard */
2356 sc_move_cursor(sc->old_scp, sc->old_scp->xpos, sc->old_scp->ypos);
2357 if (!ISGRAPHSC(sc->old_scp))
2358 sc_remove_cursor_image(sc->old_scp);
2359 if (sc->old_scp->kbd_mode == K_XLATE)
2360 save_kbd_state(sc->old_scp);
2362 /* set up the video for the new screen */
2363 scp = sc->cur_scp = sc->new_scp;
2364 if (sc->old_scp->mode != scp->mode || ISUNKNOWNSC(sc->old_scp))
2367 sc_vtb_init(&scp->scr, VTB_FRAMEBUFFER, scp->xsize, scp->ysize,
2368 (void *)sc->adp->va_window, FALSE);
2369 scp->status |= MOUSE_HIDDEN;
2370 sc_move_cursor(scp, scp->xpos, scp->ypos);
2371 if (!ISGRAPHSC(scp))
2372 sc_set_cursor_image(scp);
2373 #ifndef SC_NO_PALETTE_LOADING
2374 if (ISGRAPHSC(sc->old_scp))
2375 load_palette(sc->adp, sc->palette);
2377 sc_set_border(scp, scp->border);
2379 /* set up the keyboard for the new screen */
2380 if (sc->old_scp->kbd_mode != scp->kbd_mode)
2381 kbd_ioctl(sc->kbd, KDSKBMODE, (caddr_t)&scp->kbd_mode);
2382 update_kbd_state(scp, scp->status, LOCK_MASK);
2388 sc_puts(scr_stat *scp, u_char *buf, int len)
2391 /* make screensaver happy */
2392 if (!sticky_splash && scp == scp->sc->cur_scp)
2393 run_scrn_saver = FALSE;
2397 (*scp->tsw->te_puts)(scp, buf, len);
2399 if (scp->sc->delayed_next_scr)
2400 sc_switch_scr(scp->sc, scp->sc->delayed_next_scr - 1);
2404 sc_draw_cursor_image(scr_stat *scp)
2406 /* assert(scp == scp->sc->cur_scp); */
2407 ++scp->sc->videoio_in_progress;
2408 (*scp->rndr->draw_cursor)(scp, scp->cursor_pos,
2409 scp->sc->flags & SC_BLINK_CURSOR, TRUE,
2410 sc_inside_cutmark(scp, scp->cursor_pos));
2411 scp->cursor_oldpos = scp->cursor_pos;
2412 --scp->sc->videoio_in_progress;
2416 sc_remove_cursor_image(scr_stat *scp)
2418 /* assert(scp == scp->sc->cur_scp); */
2419 ++scp->sc->videoio_in_progress;
2420 (*scp->rndr->draw_cursor)(scp, scp->cursor_oldpos,
2421 scp->sc->flags & SC_BLINK_CURSOR, FALSE,
2422 sc_inside_cutmark(scp, scp->cursor_oldpos));
2423 --scp->sc->videoio_in_progress;
2427 update_cursor_image(scr_stat *scp)
2431 if (scp->sc->flags & SC_CHAR_CURSOR) {
2432 scp->cursor_base = imax(0, scp->sc->cursor_base);
2433 scp->cursor_height = imin(scp->sc->cursor_height, scp->font_size);
2435 scp->cursor_base = 0;
2436 scp->cursor_height = scp->font_size;
2438 blink = scp->sc->flags & SC_BLINK_CURSOR;
2440 /* assert(scp == scp->sc->cur_scp); */
2441 ++scp->sc->videoio_in_progress;
2442 (*scp->rndr->draw_cursor)(scp, scp->cursor_oldpos, blink, FALSE,
2443 sc_inside_cutmark(scp, scp->cursor_pos));
2444 (*scp->rndr->set_cursor)(scp, scp->cursor_base, scp->cursor_height, blink);
2445 (*scp->rndr->draw_cursor)(scp, scp->cursor_pos, blink, TRUE,
2446 sc_inside_cutmark(scp, scp->cursor_pos));
2447 --scp->sc->videoio_in_progress;
2451 sc_set_cursor_image(scr_stat *scp)
2453 if (scp->sc->flags & SC_CHAR_CURSOR) {
2454 scp->cursor_base = imax(0, scp->sc->cursor_base);
2455 scp->cursor_height = imin(scp->sc->cursor_height, scp->font_size);
2457 scp->cursor_base = 0;
2458 scp->cursor_height = scp->font_size;
2461 /* assert(scp == scp->sc->cur_scp); */
2462 ++scp->sc->videoio_in_progress;
2463 (*scp->rndr->set_cursor)(scp, scp->cursor_base, scp->cursor_height,
2464 scp->sc->flags & SC_BLINK_CURSOR);
2465 --scp->sc->videoio_in_progress;
2469 scinit(int unit, int flags)
2472 * When syscons is being initialized as the kernel console, malloc()
2473 * is not yet functional, because various kernel structures has not been
2474 * fully initialized yet. Therefore, we need to declare the following
2475 * static buffers for the console. This is less than ideal,
2476 * but is necessry evil for the time being. XXX
2478 static scr_stat main_console;
2479 static u_short sc_buffer[ROW*COL]; /* XXX */
2480 #ifndef SC_NO_FONT_LOADING
2481 static u_char font_8[256*8];
2482 static u_char font_14[256*14];
2483 static u_char font_16[256*16];
2488 video_adapter_t *adp;
2493 /* one time initialization */
2494 if (init_done == COLD)
2495 sc_get_bios_values(&bios_value);
2499 * Allocate resources. Even if we are being called for the second
2500 * time, we must allocate them again, because they might have
2503 sc = sc_get_softc(unit, flags & SC_KERNEL_CONSOLE);
2505 if (sc->adapter >= 0) {
2506 vid_release(sc->adp, (void *)&sc->adapter);
2510 if (sc->keyboard >= 0) {
2511 DPRINTF(5, ("sc%d: releasing kbd%d\n", unit, sc->keyboard));
2512 i = kbd_release(sc->kbd, (void *)&sc->keyboard);
2513 DPRINTF(5, ("sc%d: kbd_release returned %d\n", unit, i));
2514 if (sc->kbd != NULL) {
2515 DPRINTF(5, ("sc%d: kbd != NULL!, index:%d, unit:%d, flags:0x%x\n",
2516 unit, sc->kbd->kb_index, sc->kbd->kb_unit, sc->kbd->kb_flags));
2520 sc->adapter = vid_allocate("*", unit, (void *)&sc->adapter);
2521 sc->adp = vid_get_adapter(sc->adapter);
2522 /* assert((sc->adapter >= 0) && (sc->adp != NULL)) */
2523 sc->keyboard = sc_allocate_keyboard(sc, unit);
2524 DPRINTF(1, ("sc%d: keyboard %d\n", unit, sc->keyboard));
2525 sc->kbd = kbd_get_keyboard(sc->keyboard);
2526 if (sc->kbd != NULL) {
2527 DPRINTF(1, ("sc%d: kbd index:%d, unit:%d, flags:0x%x\n",
2528 unit, sc->kbd->kb_index, sc->kbd->kb_unit, sc->kbd->kb_flags));
2531 if (!(sc->flags & SC_INIT_DONE) || (adp != sc->adp)) {
2533 sc->initial_mode = sc->adp->va_initial_mode;
2535 #ifndef SC_NO_FONT_LOADING
2536 if (flags & SC_KERNEL_CONSOLE) {
2537 sc->font_8 = font_8;
2538 sc->font_14 = font_14;
2539 sc->font_16 = font_16;
2540 } else if (sc->font_8 == NULL) {
2541 /* assert(sc_malloc) */
2542 sc->font_8 = kmalloc(sizeof(font_8), M_SYSCONS, M_WAITOK);
2543 sc->font_14 = kmalloc(sizeof(font_14), M_SYSCONS, M_WAITOK);
2544 sc->font_16 = kmalloc(sizeof(font_16), M_SYSCONS, M_WAITOK);
2548 /* extract the hardware cursor location and hide the cursor for now */
2549 (*vidsw[sc->adapter]->read_hw_cursor)(sc->adp, &col, &row);
2550 (*vidsw[sc->adapter]->set_hw_cursor)(sc->adp, -1, -1);
2552 /* set up the first console */
2553 sc->first_vty = unit*MAXCONS;
2554 sc->vtys = MAXCONS; /* XXX: should be configurable */
2555 if (flags & SC_KERNEL_CONSOLE) {
2556 scp = &main_console;
2557 sc->console_scp = scp;
2558 init_scp(sc, sc->first_vty, scp);
2559 sc_vtb_init(&scp->vtb, VTB_MEMORY, scp->xsize, scp->ysize,
2560 (void *)sc_buffer, FALSE);
2561 if (sc_init_emulator(scp, SC_DFLT_TERM))
2562 sc_init_emulator(scp, "*");
2563 (*scp->tsw->te_default_attr)(scp,
2564 kernel_default.std_color,
2565 kernel_default.rev_color);
2567 /* assert(sc_malloc) */
2568 sc->dev = kmalloc(sizeof(cdev_t)*sc->vtys, M_SYSCONS, M_WAITOK | M_ZERO);
2570 sc->dev[0] = make_dev(&sc_ops, unit*MAXCONS, UID_ROOT,
2571 GID_WHEEL, 0600, "ttyv%r", unit*MAXCONS);
2573 sc->dev[0]->si_tty = ttymalloc(sc->dev[0]->si_tty);
2574 scp = alloc_scp(sc, sc->first_vty);
2575 sc->dev[0]->si_drv1 = scp;
2579 /* copy screen to temporary buffer */
2580 sc_vtb_init(&scp->scr, VTB_FRAMEBUFFER, scp->xsize, scp->ysize,
2581 (void *)scp->sc->adp->va_window, FALSE);
2583 sc_vtb_copy(&scp->scr, 0, &scp->vtb, 0, scp->xsize*scp->ysize);
2585 /* move cursors to the initial positions */
2586 if (col >= scp->xsize)
2588 if (row >= scp->ysize)
2589 row = scp->ysize - 1;
2592 scp->cursor_pos = scp->cursor_oldpos = row*scp->xsize + col;
2593 if (bios_value.cursor_end < scp->font_size)
2594 sc->cursor_base = scp->font_size - bios_value.cursor_end - 1;
2596 sc->cursor_base = 0;
2597 i = bios_value.cursor_end - bios_value.cursor_start + 1;
2598 sc->cursor_height = imin(i, scp->font_size);
2599 #ifndef SC_NO_SYSMOUSE
2600 sc_mouse_move(scp, scp->xpixel/2, scp->ypixel/2);
2602 if (!ISGRAPHSC(scp)) {
2603 sc_set_cursor_image(scp);
2604 sc_draw_cursor_image(scp);
2607 /* save font and palette */
2608 #ifndef SC_NO_FONT_LOADING
2609 sc->fonts_loaded = 0;
2610 if (ISFONTAVAIL(sc->adp->va_flags)) {
2612 bcopy(dflt_font_8, sc->font_8, sizeof(dflt_font_8));
2613 bcopy(dflt_font_14, sc->font_14, sizeof(dflt_font_14));
2614 bcopy(dflt_font_16, sc->font_16, sizeof(dflt_font_16));
2615 sc->fonts_loaded = FONT_16 | FONT_14 | FONT_8;
2616 if (scp->font_size < 14) {
2617 sc_load_font(scp, 0, 8, sc->font_8, 0, 256);
2618 } else if (scp->font_size >= 16) {
2619 sc_load_font(scp, 0, 16, sc->font_16, 0, 256);
2621 sc_load_font(scp, 0, 14, sc->font_14, 0, 256);
2623 #else /* !SC_DFLT_FONT */
2624 if (scp->font_size < 14) {
2625 sc_save_font(scp, 0, 8, sc->font_8, 0, 256);
2626 sc->fonts_loaded = FONT_8;
2627 } else if (scp->font_size >= 16) {
2628 sc_save_font(scp, 0, 16, sc->font_16, 0, 256);
2629 sc->fonts_loaded = FONT_16;
2631 sc_save_font(scp, 0, 14, sc->font_14, 0, 256);
2632 sc->fonts_loaded = FONT_14;
2634 #endif /* SC_DFLT_FONT */
2635 /* FONT KLUDGE: always use the font page #0. XXX */
2636 sc_show_font(scp, 0);
2638 #endif /* !SC_NO_FONT_LOADING */
2640 #ifndef SC_NO_PALETTE_LOADING
2641 save_palette(sc->adp, sc->palette);
2645 if (!(sc->flags & SC_SPLASH_SCRN) && (flags & SC_KERNEL_CONSOLE)) {
2646 /* we are ready to put up the splash image! */
2647 splash_init(sc->adp, scsplash_callback, sc);
2648 sc->flags |= SC_SPLASH_SCRN;
2650 #endif /* NSPLASH */
2653 /* the rest is not necessary, if we have done it once */
2654 if (sc->flags & SC_INIT_DONE)
2657 /* initialize mapscrn arrays to a one to one map */
2658 for (i = 0; i < sizeof(sc->scr_map); i++)
2659 sc->scr_map[i] = sc->scr_rmap[i] = i;
2661 sc->flags |= SC_INIT_DONE;
2665 scterm(int unit, int flags)
2670 sc = sc_get_softc(unit, flags & SC_KERNEL_CONSOLE);
2672 return; /* shouldn't happen */
2675 /* this console is no longer available for the splash screen */
2676 if (sc->flags & SC_SPLASH_SCRN) {
2677 splash_term(sc->adp);
2678 sc->flags &= ~SC_SPLASH_SCRN;
2680 #endif /* NSPLASH */
2683 /* move the hardware cursor to the upper-left corner */
2684 (*vidsw[sc->adapter]->set_hw_cursor)(sc->adp, 0, 0);
2687 /* release the keyboard and the video card */
2688 if (sc->keyboard >= 0)
2689 kbd_release(sc->kbd, &sc->keyboard);
2690 if (sc->adapter >= 0)
2691 vid_release(sc->adp, &sc->adapter);
2694 * Stop the terminal emulator, if any. If operating on the
2695 * kernel console sc->dev may not be setup yet.
2697 if (flags & SC_KERNEL_CONSOLE)
2698 scp = sc->console_scp;
2700 scp = SC_STAT(sc->dev[0]);
2702 (*scp->tsw->te_term)(scp, &scp->ts);
2703 if (scp->ts != NULL)
2704 kfree(scp->ts, M_SYSCONS);
2706 /* clear the structure */
2707 if (!(flags & SC_KERNEL_CONSOLE)) {
2708 /* XXX: We need delete_dev() for this */
2709 kfree(sc->dev, M_SYSCONS);
2711 /* XXX: We need a ttyunregister for this */
2712 kfree(sc->tty, M_SYSCONS);
2714 #ifndef SC_NO_FONT_LOADING
2715 kfree(sc->font_8, M_SYSCONS);
2716 kfree(sc->font_14, M_SYSCONS);
2717 kfree(sc->font_16, M_SYSCONS);
2719 /* XXX vtb, history */
2721 bzero(sc, sizeof(*sc));
2727 scshutdown(void *arg, int howto)
2729 /* assert(sc_console != NULL) */
2731 sc_touch_scrn_saver();
2732 if (!cold && sc_console
2733 && sc_console->sc->cur_scp->smode.mode == VT_AUTO
2734 && sc_console->smode.mode == VT_AUTO)
2735 sc_switch_scr(sc_console->sc, sc_console->index);
2736 shutdown_in_progress = TRUE;
2740 sc_clean_up(scr_stat *scp)
2744 #endif /* NSPLASH */
2746 if (scp->sc->flags & SC_SCRN_BLANKED) {
2747 sc_touch_scrn_saver();
2749 if ((error = wait_scrn_saver_stop(scp->sc)))
2751 #endif /* NSPLASH */
2753 scp->status |= MOUSE_HIDDEN;
2754 sc_remove_mouse_image(scp);
2755 sc_remove_cutmarking(scp);
2760 sc_alloc_scr_buffer(scr_stat *scp, int wait, int discard)
2766 sc_vtb_init(&new, VTB_MEMORY, scp->xsize, scp->ysize, NULL, wait);
2767 if (!discard && (old.vtb_flags & VTB_VALID)) {
2768 /* retain the current cursor position and buffer contants */
2769 scp->cursor_oldpos = scp->cursor_pos;
2771 * This works only if the old buffer has the same size as or larger
2772 * than the new one. XXX
2774 sc_vtb_copy(&old, 0, &new, 0, scp->xsize*scp->ysize);
2778 sc_vtb_destroy(&old);
2781 #ifndef SC_NO_SYSMOUSE
2782 /* move the mouse cursor at the center of the screen */
2783 sc_mouse_move(scp, scp->xpixel / 2, scp->ypixel / 2);
2788 alloc_scp(sc_softc_t *sc, int vty)
2792 /* assert(sc_malloc) */
2794 scp = kmalloc(sizeof(scr_stat), M_SYSCONS, M_WAITOK);
2795 init_scp(sc, vty, scp);
2797 sc_alloc_scr_buffer(scp, TRUE, TRUE);
2798 if (sc_init_emulator(scp, SC_DFLT_TERM))
2799 sc_init_emulator(scp, "*");
2801 #ifndef SC_NO_CUTPASTE
2802 sc_alloc_cut_buffer(scp, TRUE);
2805 #ifndef SC_NO_HISTORY
2806 sc_alloc_history_buffer(scp, 0, 0, TRUE);
2813 init_scp(sc_softc_t *sc, int vty, scr_stat *scp)
2817 bzero(scp, sizeof(*scp));
2822 scp->mode = sc->initial_mode;
2823 callout_init(&scp->blink_screen_ch);
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 scp->rndr->init(scp);
2922 sc_clear_screen(scp);
2923 /* assert(error == 0); */
2927 if (sc_malloc && (sw->te_size > 0))
2928 p = kmalloc(sw->te_size, M_SYSCONS, M_NOWAIT);
2931 error = (*sw->te_init)(scp, &p, SC_TE_COLD_INIT);
2936 (*scp->tsw->te_term)(scp, &scp->ts);
2937 if (scp->ts != NULL)
2938 kfree(scp->ts, M_SYSCONS);
2942 scp->rndr->init(scp);
2945 (*sw->te_default_attr)(scp, user_default.std_color, user_default.rev_color);
2946 sc_clear_screen(scp);
2952 * scgetc(flags) - get character from keyboard.
2953 * If flags & SCGETC_CN, then avoid harmful side effects.
2954 * If flags & SCGETC_NONBLOCK, then wait until a key is pressed, else
2955 * return NOKEY if there is nothing there.
2958 scgetc(sc_softc_t *sc, u_int flags)
2961 #ifndef SC_NO_HISTORY
2969 if (sc->kbd == NULL)
2974 /* I don't like this, but... XXX */
2975 if (flags & SCGETC_CN)
2976 sccnupdate(sc->cur_scp);
2979 /* first see if there is something in the keyboard port */
2981 c = kbd_read_char(sc->kbd, !(flags & SCGETC_NONBLOCK));
2983 if (!(flags & SCGETC_CN))
2984 sc_bell(scp, bios_value.bell_pitch, BELL_DURATION);
2985 } else if (c == NOKEY)
2991 /* make screensaver happy */
2993 sc_touch_scrn_saver();
2995 if (!(flags & SCGETC_CN))
2996 /* do the /dev/random device a favour */
2997 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 kprintf("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(struct dev_mmap_args *ap)
3236 scp = SC_STAT(ap->a_head.a_dev);
3237 if (scp != scp->sc->cur_scp)
3239 ap->a_result = (*vidsw[scp->sc->adapter]->mmap)(scp->sc->adp, ap->a_offset,
3245 save_kbd_state(scr_stat *scp)
3250 error = kbd_ioctl(scp->sc->kbd, KDGKBSTATE, (caddr_t)&state);
3251 if (error == ENOIOCTL)
3254 scp->status &= ~LOCK_MASK;
3255 scp->status |= state;
3261 update_kbd_state(scr_stat *scp, int new_bits, int mask)
3266 if (mask != LOCK_MASK) {
3267 error = kbd_ioctl(scp->sc->kbd, KDGKBSTATE, (caddr_t)&state);
3268 if (error == ENOIOCTL)
3273 state |= new_bits & mask;
3275 state = new_bits & LOCK_MASK;
3277 error = kbd_ioctl(scp->sc->kbd, KDSKBSTATE, (caddr_t)&state);
3278 if (error == ENOIOCTL)
3284 update_kbd_leds(scr_stat *scp, int which)
3289 error = kbd_ioctl(scp->sc->kbd, KDSETLED, (caddr_t)&which);
3290 if (error == ENOIOCTL)
3296 set_mode(scr_stat *scp)
3300 /* reject unsupported mode */
3301 if ((*vidsw[scp->sc->adapter]->get_info)(scp->sc->adp, scp->mode, &info))
3304 /* if this vty is not currently showing, do nothing */
3305 if (scp != scp->sc->cur_scp)
3308 /* setup video hardware for the given mode */
3309 (*vidsw[scp->sc->adapter]->set_mode)(scp->sc->adp, scp->mode);
3310 scp->rndr->init(scp);
3311 sc_vtb_init(&scp->scr, VTB_FRAMEBUFFER, scp->xsize, scp->ysize,
3312 (void *)scp->sc->adp->va_window, FALSE);
3314 #ifndef SC_NO_FONT_LOADING
3315 /* load appropriate font */
3316 if (!(scp->status & GRAPHICS_MODE)) {
3317 if (!(scp->status & PIXEL_MODE) && ISFONTAVAIL(scp->sc->adp->va_flags)) {
3318 if (scp->font_size < 14) {
3319 if (scp->sc->fonts_loaded & FONT_8)
3320 sc_load_font(scp, 0, 8, scp->sc->font_8, 0, 256);
3321 } else if (scp->font_size >= 16) {
3322 if (scp->sc->fonts_loaded & FONT_16)
3323 sc_load_font(scp, 0, 16, scp->sc->font_16, 0, 256);
3325 if (scp->sc->fonts_loaded & FONT_14)
3326 sc_load_font(scp, 0, 14, scp->sc->font_14, 0, 256);
3330 * This is an interim kludge to display correct font.
3331 * Always use the font page #0 on the video plane 2.
3332 * Somehow we cannot show the font in other font pages on
3333 * some video cards... XXX
3335 sc_show_font(scp, 0);
3339 #endif /* !SC_NO_FONT_LOADING */
3341 sc_set_border(scp, scp->border);
3342 sc_set_cursor_image(scp);
3348 refresh_ega_palette(scr_stat *scp)
3352 int rsize, gsize, bsize;
3353 int rfld, gfld, bfld;
3356 rsize = scp->sc->adp->va_info.vi_pixel_fsizes[0];
3357 gsize = scp->sc->adp->va_info.vi_pixel_fsizes[1];
3358 bsize = scp->sc->adp->va_info.vi_pixel_fsizes[2];
3359 rfld = scp->sc->adp->va_info.vi_pixel_fields[0];
3360 gfld = scp->sc->adp->va_info.vi_pixel_fields[1];
3361 bfld = scp->sc->adp->va_info.vi_pixel_fields[2];
3363 for (i = 0; i < 16; i++) {
3364 reg = scp->sc->adp->va_palette_regs[i];
3366 r = scp->sc->palette[reg * 3] >> (8 - rsize);
3367 g = scp->sc->palette[reg * 3 + 1] >> (8 - gsize);
3368 b = scp->sc->palette[reg * 3 + 2] >> (8 - bsize);
3370 scp->ega_palette[i] = (r << rfld) + (g << gfld) + (b << bfld);
3375 sc_set_border(scr_stat *scp, int color)
3377 ++scp->sc->videoio_in_progress;
3378 (*scp->rndr->draw_border)(scp, color);
3379 --scp->sc->videoio_in_progress;
3382 #ifndef SC_NO_FONT_LOADING
3384 sc_load_font(scr_stat *scp, int page, int size, u_char *buf,
3385 int base, int count)
3390 sc->font_loading_in_progress = TRUE;
3391 (*vidsw[sc->adapter]->load_font)(sc->adp, page, size, buf, base, count);
3392 sc->font_loading_in_progress = FALSE;
3396 sc_save_font(scr_stat *scp, int page, int size, u_char *buf,
3397 int base, int count)
3402 sc->font_loading_in_progress = TRUE;
3403 (*vidsw[sc->adapter]->save_font)(sc->adp, page, size, buf, base, count);
3404 sc->font_loading_in_progress = FALSE;
3408 sc_show_font(scr_stat *scp, int page)
3410 (*vidsw[scp->sc->adapter]->show_font)(scp->sc->adp, page);
3412 #endif /* !SC_NO_FONT_LOADING */
3415 sc_paste(scr_stat *scp, u_char *p, int count)
3420 if (scp->status & MOUSE_VISIBLE) {
3421 tp = VIRTUAL_TTY(scp->sc, scp->sc->cur_scp->index);
3424 rmap = scp->sc->scr_rmap;
3425 for (; count > 0; --count)
3426 (*linesw[tp->t_line].l_rint)(rmap[*p++], tp);
3431 sc_bell(scr_stat *scp, int pitch, int duration)
3433 if (cold || shutdown_in_progress)
3436 if (scp != scp->sc->cur_scp && (scp->sc->flags & SC_QUIET_BELL))
3439 if (scp->sc->flags & SC_VISUAL_BELL) {
3440 if (scp->sc->blink_in_progress)
3442 scp->sc->blink_in_progress = 3;
3443 if (scp != scp->sc->cur_scp)
3444 scp->sc->blink_in_progress += 2;
3445 blink_screen(scp->sc->cur_scp);
3446 } else if (duration != 0 && pitch != 0) {
3447 if (scp != scp->sc->cur_scp)
3449 sysbeep(pitch, duration);
3454 blink_screen(void *arg)
3456 scr_stat *scp = arg;
3459 if (ISGRAPHSC(scp) || (scp->sc->blink_in_progress <= 1)) {
3460 scp->sc->blink_in_progress = 0;
3462 tp = VIRTUAL_TTY(scp->sc, scp->index);
3465 if (scp->sc->delayed_next_scr)
3466 sc_switch_scr(scp->sc, scp->sc->delayed_next_scr - 1);
3469 (*scp->rndr->draw)(scp, 0, scp->xsize*scp->ysize,
3470 scp->sc->blink_in_progress & 1);
3471 scp->sc->blink_in_progress--;
3472 callout_reset(&scp->blink_screen_ch, hz / 10, blink_screen, scp);
3478 * Allocate active keyboard. Try to allocate "kbdmux" keyboard first, and,
3479 * if found, add all non-busy keyboards to "kbdmux". Otherwise look for
3484 sc_allocate_keyboard(sc_softc_t *sc, int unit)
3490 idx0 = kbd_allocate("kbdmux", -1, (void *)&sc->keyboard, sckbdevent, sc);
3492 k0 = kbd_get_keyboard(idx0);
3494 for (idx = kbd_find_keyboard2("*", -1, 0, 0);
3496 idx = kbd_find_keyboard2("*", -1, idx + 1, 0)) {
3497 k = kbd_get_keyboard(idx);
3499 if (idx == idx0 || KBD_IS_BUSY(k))
3502 bzero(&ki, sizeof(ki));
3503 strcpy(ki.kb_name, k->kb_name);
3504 ki.kb_unit = k->kb_unit;
3506 kbd_ioctl(k0, KBADDKBD, (caddr_t) &ki);
3509 idx0 = kbd_allocate("*", unit, (void *)&sc->keyboard, sckbdevent, sc);