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>
56 #include <sys/thread2.h>
57 #include <sys/spinlock2.h>
59 #include <machine/clock.h>
60 #include <machine/console.h>
61 #include <machine/psl.h>
62 #include <machine/pc/display.h>
64 #include <machine/apm_bios.h>
66 #include <machine/frame.h>
68 #include <dev/misc/kbd/kbdreg.h>
69 #include <dev/video/fb/fbreg.h>
70 #include <dev/video/fb/splashreg.h>
76 #define DEFAULT_BLANKTIME (5*60) /* 5 minutes */
77 #define MAX_BLANKTIME (7*24*60*60) /* 7 days!? */
79 #define KEYCODE_BS 0x0e /* "<-- Backspace" key, XXX */
81 MALLOC_DEFINE(M_SYSCONS, "syscons", "Syscons");
83 typedef struct default_attr {
84 int std_color; /* normal hardware color */
85 int rev_color; /* reverse hardware color */
88 static default_attr user_default = {
93 static default_attr kernel_default = {
95 SC_KERNEL_CONS_REV_ATTR,
98 static int sc_console_unit = -1;
99 static scr_stat *sc_console;
100 static struct tty *sc_console_tty;
101 static void *kernel_console_ts;
103 static char init_done = COLD;
104 static char shutdown_in_progress = FALSE;
105 static char sc_malloc = FALSE;
107 static int saver_mode = CONS_NO_SAVER; /* LKM/user saver */
108 static int run_scrn_saver = FALSE; /* should run the saver? */
109 static long scrn_blank_time = 0; /* screen saver timeout value */
111 static int scrn_blanked; /* # of blanked screen */
112 static int sticky_splash = FALSE;
114 static void none_saver(sc_softc_t *sc, int blank) { }
115 static void (*current_saver)(sc_softc_t *, int) = none_saver;
118 #if !defined(SC_NO_FONT_LOADING) && defined(SC_DFLT_FONT)
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))
135 static cdev_t cctl_dev;
136 static timeout_t blink_screen;
137 static struct spinlock syscons_spin = SPINLOCK_INITIALIZER(syscons_spin);
140 static int scvidprobe(int unit, int flags, int cons);
141 static int sckbdprobe(int unit, int flags, int cons);
142 static void scmeminit(void *arg);
143 static int scdevtounit(cdev_t dev);
144 static kbd_callback_func_t sckbdevent;
145 static int scparam(struct tty *tp, struct termios *t);
146 static void scstart(struct tty *tp);
147 static void scinit(int unit, int flags);
148 static void scterm(int unit, int flags);
149 static void scshutdown(void *arg, int howto);
150 static void sc_puts(scr_stat *scp, u_char *buf, int len);
151 static u_int scgetc(sc_softc_t *sc, u_int flags);
153 #define SCGETC_NONBLOCK 2
154 static int sccngetch(int flags);
155 static void sccnupdate(scr_stat *scp);
156 static scr_stat *alloc_scp(sc_softc_t *sc, int vty);
157 static void init_scp(sc_softc_t *sc, int vty, scr_stat *scp);
158 static timeout_t scrn_timer;
159 static int and_region(int *s1, int *e1, int s2, int e2);
160 static void scrn_update(scr_stat *scp, int show_cursor);
163 static int scsplash_callback(int event, void *arg);
164 static void scsplash_saver(sc_softc_t *sc, int show);
165 static int add_scrn_saver(void (*this_saver)(sc_softc_t *, int));
166 static int remove_scrn_saver(void (*this_saver)(sc_softc_t *, int));
167 static int set_scrn_saver_mode(scr_stat *scp, int mode, u_char *pal, int border);
168 static int restore_scrn_saver_mode(scr_stat *scp, int changemode);
169 static void stop_scrn_saver(sc_softc_t *sc, void (*saver)(sc_softc_t *, int));
170 static int wait_scrn_saver_stop(sc_softc_t *sc);
171 #define scsplash_stick(stick) (sticky_splash = (stick))
173 #define scsplash_stick(stick)
176 static void do_switch_scr(sc_softc_t *sc);
177 static int vt_proc_alive(scr_stat *scp);
178 static int signal_vt_rel(scr_stat *scp);
179 static int signal_vt_acq(scr_stat *scp);
180 static int finish_vt_rel(scr_stat *scp, int release);
181 static int finish_vt_acq(scr_stat *scp);
182 static void exchange_scr(sc_softc_t *sc);
183 static void update_cursor_image(scr_stat *scp);
184 static int save_kbd_state(scr_stat *scp);
185 static int update_kbd_state(scr_stat *scp, int state, int mask);
186 static int update_kbd_leds(scr_stat *scp, int which);
187 static int sc_allocate_keyboard(sc_softc_t *sc, int unit);
190 * Console locking daemon
195 spin_lock(&syscons_spin);
199 * Returns non-zero on success, 0 on failure.
202 syscons_lock_nonblock(void)
204 return(spin_trylock(&syscons_spin));
210 spin_unlock(&syscons_spin);
216 #define CDEV_MAJOR 12
218 static cn_probe_t sccnprobe;
219 static cn_init_t sccninit;
220 static cn_init_t sccninit_fini;
221 static cn_getc_t sccngetc;
222 static cn_checkc_t sccncheckc;
223 static cn_putc_t sccnputc;
224 static cn_dbctl_t sccndbctl;
225 static cn_term_t sccnterm;
227 CONS_DRIVER(sc, sccnprobe, sccninit, sccninit_fini, sccnterm,
228 sccngetc, sccncheckc, sccnputc, sccndbctl);
230 static d_open_t scopen;
231 static d_close_t scclose;
232 static d_read_t scread;
233 static d_ioctl_t scioctl;
234 static d_mmap_t scmmap;
236 static struct dev_ops sc_ops = {
237 { "sc", CDEV_MAJOR, D_TTY },
244 .d_kqfilter = ttykqfilter,
245 .d_revoke = ttyrevoke
249 sc_probe_unit(int unit, int flags)
251 if (!scvidprobe(unit, flags, FALSE)) {
253 kprintf("sc%d: no video adapter found.\n", unit);
257 /* syscons will be attached even when there is no keyboard */
258 sckbdprobe(unit, flags, FALSE);
263 /* probe video adapters, return TRUE if found */
265 scvidprobe(int unit, int flags, int cons)
268 * Access the video adapter driver through the back door!
269 * Video adapter drivers need to be configured before syscons.
270 * However, when syscons is being probed as the low-level console,
271 * they have not been initialized yet. We force them to initialize
272 * themselves here. XXX
274 vid_configure(cons ? VIO_PROBE_ONLY : 0);
276 return (vid_find_adapter("*", unit) >= 0);
279 /* probe the keyboard, return TRUE if found */
281 sckbdprobe(int unit, int flags, int cons)
283 /* access the keyboard driver through the backdoor! */
284 kbd_configure(cons ? KB_CONF_PROBE_ONLY : 0);
286 return (kbd_find_keyboard("*", unit) >= 0);
290 adapter_name(video_adapter_t *adp)
296 { KD_MONO, { "MDA", "MDA" } },
297 { KD_HERCULES, { "Hercules", "Hercules" } },
298 { KD_CGA, { "CGA", "CGA" } },
299 { KD_EGA, { "EGA", "EGA (mono)" } },
300 { KD_VGA, { "VGA", "VGA (mono)" } },
301 { KD_TGA, { "TGA", "TGA" } },
302 { -1, { "Unknown", "Unknown" } },
306 for (i = 0; names[i].type != -1; ++i)
307 if (names[i].type == adp->va_type)
309 return names[i].name[(adp->va_flags & V_ADP_COLOR) ? 0 : 1];
313 sc_attach_unit(int unit, int flags)
322 flags &= ~SC_KERNEL_CONSOLE;
324 if (sc_console_unit == unit) {
326 * If this unit is being used as the system console, we need to
327 * adjust some variables and buffers before and after scinit().
329 /* assert(sc_console != NULL) */
330 flags |= SC_KERNEL_CONSOLE;
335 if (sc_console->tsw->te_size > 0) {
336 /* assert(sc_console->ts != NULL); */
337 kernel_console_ts = sc_console->ts;
338 sc_console->ts = kmalloc(sc_console->tsw->te_size,
339 M_SYSCONS, M_WAITOK);
340 bcopy(kernel_console_ts, sc_console->ts, sc_console->tsw->te_size);
341 (*sc_console->tsw->te_default_attr)(sc_console,
342 user_default.std_color,
343 user_default.rev_color);
349 sc = sc_get_softc(unit, flags & SC_KERNEL_CONSOLE);
352 * If this is the console we couldn't setup sc->dev before because
353 * malloc wasn't working. Set it up now.
355 if (flags & SC_KERNEL_CONSOLE) {
356 KKASSERT(sc->dev == NULL);
357 sc->dev = kmalloc(sizeof(cdev_t)*sc->vtys, M_SYSCONS, M_WAITOK|M_ZERO);
358 sc->dev[0] = make_dev(&sc_ops, sc_console_unit*MAXCONS, UID_ROOT,
360 "ttyv%r", sc_console_unit*MAXCONS);
361 sc->dev[0]->si_tty = ttymalloc(sc->dev[0]->si_tty);
362 sc->dev[0]->si_drv1 = sc_console;
366 * Finish up the standard attach
369 callout_init(&sc->scrn_timer_ch);
370 scp = SC_STAT(sc->dev[0]);
371 if (sc_console == NULL) /* sc_console_unit < 0 */
375 if ((sc->config & SC_VESA800X600)
376 && ((*vidsw[sc->adapter]->get_info)(sc->adp, M_VESA_800x600, &info) == 0)) {
378 if (sc->flags & SC_SPLASH_SCRN)
379 splash_term(sc->adp);
381 sc_set_graphics_mode(scp, NULL, M_VESA_800x600);
382 sc_set_pixel_mode(scp, NULL, 0, 0, 16);
383 sc->initial_mode = M_VESA_800x600;
385 /* put up the splash again! */
386 if (sc->flags & SC_SPLASH_SCRN)
387 splash_init(sc->adp, scsplash_callback, sc);
390 #endif /* SC_PIXEL_MODE */
392 /* initialize cursor */
394 update_cursor_image(scp);
396 /* get screen update going */
399 /* set up the keyboard */
400 kbd_ioctl(sc->kbd, KDSKBMODE, (caddr_t)&scp->kbd_mode);
401 update_kbd_state(scp, scp->status, LOCK_MASK);
403 kprintf("sc%d: %s <%d virtual consoles, flags=0x%x>\n",
404 unit, adapter_name(sc->adp), sc->vtys, sc->config);
406 kprintf("sc%d:", unit);
407 if (sc->adapter >= 0)
408 kprintf(" fb%d", sc->adapter);
409 if (sc->keyboard >= 0)
410 kprintf(", kbd%d", sc->keyboard);
412 kprintf(", terminal emulator: %s (%s)",
413 scp->tsw->te_name, scp->tsw->te_desc);
417 /* register a shutdown callback for the kernel console */
418 if (sc_console_unit == unit)
419 EVENTHANDLER_REGISTER(shutdown_pre_sync, scshutdown,
420 (void *)(uintptr_t)unit, SHUTDOWN_PRI_DEFAULT);
425 * The first vty already has struct tty and scr_stat initialized
426 * in scinit(). The other vtys will have these structs when
429 for (vc = 1; vc < sc->vtys; vc++) {
430 dev = make_dev(&sc_ops, vc + unit * MAXCONS,
432 0600, "ttyv%r", vc + unit * MAXCONS);
435 cctl_dev = make_dev(&sc_ops, SC_CONSOLECTL,
436 UID_ROOT, GID_WHEEL, 0600, "consolectl");
437 cctl_dev->si_tty = sc_console_tty = ttymalloc(sc_console_tty);
438 cctl_dev->si_drv1 = sc_console;
450 * As soon as malloc() becomes functional, we had better allocate
451 * various buffers for the kernel console.
454 if (sc_console_unit < 0) /* sc_console == NULL */
457 /* copy the temporary buffer to the final buffer */
458 sc_alloc_scr_buffer(sc_console, TRUE, FALSE);
460 #ifndef SC_NO_CUTPASTE
461 sc_alloc_cut_buffer(sc_console, TRUE);
464 #ifndef SC_NO_HISTORY
465 /* initialize history buffer & pointers */
466 sc_alloc_history_buffer(sc_console, 0, 0, TRUE);
470 SYSINIT(sc_mem, SI_BOOT1_POST, SI_ORDER_ANY, scmeminit, NULL);
473 scdevtounit(cdev_t dev)
475 int vty = SC_VTY(dev);
477 if (vty == SC_CONSOLECTL)
478 return ((sc_console != NULL) ? sc_console->sc->unit : -1);
479 else if ((vty < 0) || (vty >= MAXCONS*sc_max_unit()))
486 scopen(struct dev_open_args *ap)
488 cdev_t dev = ap->a_head.a_dev;
496 lwkt_gettoken(&tty_token);
497 unit = scdevtounit(dev);
498 DPRINTF(5, ("scopen: dev:%d,%d, unit:%d, vty:%d\n",
499 major(dev), minor(dev), unit, SC_VTY(dev)));
501 sc = sc_get_softc(unit, (sc_console_unit == unit) ? SC_KERNEL_CONSOLE : 0);
503 lwkt_reltoken(&tty_token);
507 tp = dev->si_tty = ttymalloc(dev->si_tty);
508 tp->t_oproc = scstart;
509 tp->t_param = scparam;
510 tp->t_stop = nottystop;
514 if (!ISTTYOPEN(tp)) {
516 /* Use the current setting of the <-- key as default VERASE. */
517 /* If the Delete key is preferable, an stty is necessary */
518 if (sc->kbd != NULL) {
519 key.keynum = KEYCODE_BS;
520 kbd_ioctl(sc->kbd, GIO_KEYMAPENT, (caddr_t)&key);
521 tp->t_cc[VERASE] = key.key.map[0];
523 tp->t_iflag = TTYDEF_IFLAG;
524 tp->t_oflag = TTYDEF_OFLAG;
525 tp->t_cflag = TTYDEF_CFLAG;
526 tp->t_lflag = TTYDEF_LFLAG;
527 tp->t_ispeed = tp->t_ospeed = TTYDEF_SPEED;
528 scparam(tp, &tp->t_termios);
529 (*linesw[tp->t_line].l_modem)(tp, 1);
532 if (tp->t_state & TS_XCLUDE && priv_check_cred(ap->a_cred, PRIV_ROOT, 0)) {
533 lwkt_reltoken(&tty_token);
537 error = (*linesw[tp->t_line].l_open)(dev, tp);
541 scp = dev->si_drv1 = alloc_scp(sc, SC_VTY(dev));
543 sc_set_pixel_mode(scp, NULL, COL, ROW, 16);
545 if (!tp->t_winsize.ws_col && !tp->t_winsize.ws_row) {
546 tp->t_winsize.ws_col = scp->xsize;
547 tp->t_winsize.ws_row = scp->ysize;
550 lwkt_reltoken(&tty_token);
555 scclose(struct dev_close_args *ap)
557 cdev_t dev = ap->a_head.a_dev;
558 struct tty *tp = dev->si_tty;
562 lwkt_gettoken(&tty_token);
563 if (SC_VTY(dev) != SC_CONSOLECTL) {
564 scp = SC_STAT(tp->t_dev);
565 /* were we in the middle of the VT switching process? */
566 DPRINTF(5, ("sc%d: scclose(), ", scp->sc->unit));
567 if ((scp == scp->sc->cur_scp) && (scp->sc->unit == sc_console_unit))
568 cons_unavail = FALSE;
570 * note: must be called from a critical section because finish_vt_rel
571 * will call do_switch_scr which releases it temporarily
573 if (finish_vt_rel(scp, TRUE) == 0) /* force release */
574 DPRINTF(5, ("reset WAIT_REL, "));
575 if (finish_vt_acq(scp) == 0) /* force acknowledge */
576 DPRINTF(5, ("reset WAIT_ACQ, "));
578 if (scp == &main_console) {
581 scp->smode.mode = VT_AUTO;
584 sc_vtb_destroy(&scp->vtb);
585 sc_vtb_destroy(&scp->scr);
586 sc_free_history_buffer(scp, scp->ysize);
588 kfree(scp, M_SYSCONS);
593 scp->smode.mode = VT_AUTO;
595 scp->kbd_mode = K_XLATE;
596 if (scp == scp->sc->cur_scp)
597 kbd_ioctl(scp->sc->kbd, KDSKBMODE, (caddr_t)&scp->kbd_mode);
598 DPRINTF(5, ("done.\n"));
600 (*linesw[tp->t_line].l_close)(tp, ap->a_fflag);
602 lwkt_reltoken(&tty_token);
609 scread(struct dev_read_args *ap)
613 lwkt_gettoken(&tty_token);
614 sc_touch_scrn_saver();
616 lwkt_reltoken(&tty_token);
621 sckbdevent(keyboard_t *thiskbd, int event, void *arg)
629 lwkt_gettoken(&tty_token);
631 * WARNING: In early boot sc->dev may not be setup yet.
633 sc = (sc_softc_t *)arg;
634 /* assert(thiskbd == sc->kbd) */
639 case KBDIO_UNLOADING:
642 kbd_release(thiskbd, (void *)&sc->keyboard);
643 lwkt_reltoken(&tty_token);
646 lwkt_reltoken(&tty_token);
651 * Loop while there is still input to get from the keyboard.
652 * I don't think this is nessesary, and it doesn't fix
653 * the Xaccel-2.1 keyboard hang, but it can't hurt. XXX
655 while ((c = scgetc(sc, SCGETC_NONBLOCK)) != NOKEY) {
656 cur_tty = VIRTUAL_TTY(sc, sc->cur_scp->index);
657 if (!ISTTYOPEN(cur_tty)) {
658 cur_tty = sc_console_tty;
659 if (!ISTTYOPEN(cur_tty))
663 if ((*sc->cur_scp->tsw->te_input)(sc->cur_scp, c, cur_tty))
666 switch (KEYFLAGS(c)) {
667 case 0x0000: /* normal key */
668 (*linesw[cur_tty->t_line].l_rint)(KEYCHAR(c), cur_tty);
670 case FKEY: /* function key, return string */
671 cp = kbd_get_fkeystr(thiskbd, KEYCHAR(c), &len);
674 (*linesw[cur_tty->t_line].l_rint)(*cp++, cur_tty);
677 case MKEY: /* meta is active, prepend ESC */
678 (*linesw[cur_tty->t_line].l_rint)(0x1b, cur_tty);
679 (*linesw[cur_tty->t_line].l_rint)(KEYCHAR(c), cur_tty);
681 case BKEY: /* backtab fixed sequence (esc [ Z) */
682 (*linesw[cur_tty->t_line].l_rint)(0x1b, cur_tty);
683 (*linesw[cur_tty->t_line].l_rint)('[', cur_tty);
684 (*linesw[cur_tty->t_line].l_rint)('Z', cur_tty);
689 sc->cur_scp->status |= MOUSE_HIDDEN;
691 lwkt_reltoken(&tty_token);
696 scparam(struct tty *tp, struct termios *t)
698 lwkt_gettoken(&tty_token);
699 tp->t_ispeed = t->c_ispeed;
700 tp->t_ospeed = t->c_ospeed;
701 tp->t_cflag = t->c_cflag;
702 lwkt_reltoken(&tty_token);
707 scioctl(struct dev_ioctl_args *ap)
709 cdev_t dev = ap->a_head.a_dev;
710 u_long cmd = ap->a_cmd;
711 caddr_t data = ap->a_data;
712 int flag = ap->a_fflag;
719 lwkt_gettoken(&tty_token);
722 error = sc_vid_ioctl(tp, cmd, data, flag);
723 if (error != ENOIOCTL) {
724 lwkt_reltoken(&tty_token);
728 #ifndef SC_NO_HISTORY
729 error = sc_hist_ioctl(tp, cmd, data, flag);
730 if (error != ENOIOCTL) {
731 lwkt_reltoken(&tty_token);
736 #ifndef SC_NO_SYSMOUSE
737 error = sc_mouse_ioctl(tp, cmd, data, flag);
738 if (error != ENOIOCTL) {
739 lwkt_reltoken(&tty_token);
744 scp = SC_STAT(tp->t_dev);
745 /* assert(scp != NULL) */
746 /* scp is sc_console, if SC_VTY(dev) == SC_CONSOLECTL. */
750 error = (*scp->tsw->te_ioctl)(scp, tp, cmd, data, flag);
751 if (error != ENOIOCTL) {
752 lwkt_reltoken(&tty_token);
757 switch (cmd) { /* process console hardware related ioctl's */
759 case GIO_ATTR: /* get current attributes */
760 /* this ioctl is not processed here, but in the terminal emulator */
761 lwkt_reltoken(&tty_token);
764 case GIO_COLOR: /* is this a color console ? */
765 *(int *)data = (sc->adp->va_flags & V_ADP_COLOR) ? 1 : 0;
766 lwkt_reltoken(&tty_token);
769 case CONS_BLANKTIME: /* set screen saver timeout (0 = no saver) */
770 if (*(int *)data < 0 || *(int *)data > MAX_BLANKTIME) {
771 lwkt_reltoken(&tty_token);
775 scrn_blank_time = *(int *)data;
776 run_scrn_saver = (scrn_blank_time != 0);
778 lwkt_reltoken(&tty_token);
781 case CONS_CURSORTYPE: /* set cursor type blink/noblink */
783 if (!ISGRAPHSC(sc->cur_scp))
784 sc_remove_cursor_image(sc->cur_scp);
785 if ((*(int*)data) & 0x01)
786 sc->flags |= SC_BLINK_CURSOR;
788 sc->flags &= ~SC_BLINK_CURSOR;
789 if ((*(int*)data) & 0x02) {
790 sc->flags |= SC_CHAR_CURSOR;
792 sc->flags &= ~SC_CHAR_CURSOR;
794 * The cursor shape is global property; all virtual consoles
795 * are affected. Update the cursor in the current console...
797 if (!ISGRAPHSC(sc->cur_scp)) {
798 sc_set_cursor_image(sc->cur_scp);
799 sc_draw_cursor_image(sc->cur_scp);
802 lwkt_reltoken(&tty_token);
805 case CONS_BELLTYPE: /* set bell type sound/visual */
806 if ((*(int *)data) & 0x01)
807 sc->flags |= SC_VISUAL_BELL;
809 sc->flags &= ~SC_VISUAL_BELL;
810 if ((*(int *)data) & 0x02)
811 sc->flags |= SC_QUIET_BELL;
813 sc->flags &= ~SC_QUIET_BELL;
814 lwkt_reltoken(&tty_token);
817 case CONS_GETINFO: /* get current (virtual) console info */
819 vid_info_t *ptr = (vid_info_t*)data;
820 if (ptr->size == sizeof(struct vid_info)) {
821 ptr->m_num = sc->cur_scp->index;
822 ptr->font_size = scp->font_size;
823 ptr->mv_col = scp->xpos;
824 ptr->mv_row = scp->ypos;
825 ptr->mv_csz = scp->xsize;
826 ptr->mv_rsz = scp->ysize;
828 * The following fields are filled by the terminal emulator. XXX
835 ptr->mv_grfc.fore = 0; /* not supported */
836 ptr->mv_grfc.back = 0; /* not supported */
837 ptr->mv_ovscan = scp->border;
838 if (scp == sc->cur_scp)
840 ptr->mk_keylock = scp->status & LOCK_MASK;
841 lwkt_reltoken(&tty_token);
844 lwkt_reltoken(&tty_token);
848 case CONS_GETVERS: /* get version number */
849 *(int*)data = 0x200; /* version 2.0 */
850 lwkt_reltoken(&tty_token);
853 case CONS_IDLE: /* see if the screen has been idle */
855 * When the screen is in the GRAPHICS_MODE or UNKNOWN_MODE,
856 * the user process may have been writing something on the
857 * screen and syscons is not aware of it. Declare the screen
858 * is NOT idle if it is in one of these modes. But there is
859 * an exception to it; if a screen saver is running in the
860 * graphics mode in the current screen, we should say that the
861 * screen has been idle.
863 *(int *)data = (sc->flags & SC_SCRN_IDLE)
864 && (!ISGRAPHSC(sc->cur_scp)
865 || (sc->cur_scp->status & SAVER_RUNNING));
866 lwkt_reltoken(&tty_token);
869 case CONS_SAVERMODE: /* set saver mode */
870 switch(*(int *)data) {
873 /* if a LKM screen saver is running, stop it first. */
874 scsplash_stick(FALSE);
875 saver_mode = *(int *)data;
878 if ((error = wait_scrn_saver_stop(NULL))) {
880 lwkt_reltoken(&tty_token);
884 run_scrn_saver = TRUE;
885 if (saver_mode == CONS_USR_SAVER)
886 scp->status |= SAVER_RUNNING;
888 scp->status &= ~SAVER_RUNNING;
889 scsplash_stick(TRUE);
894 if ((saver_mode == CONS_USR_SAVER) && (scp->status & SAVER_RUNNING))
895 scp->status &= ~SAVER_RUNNING;
896 saver_mode = *(int *)data;
900 lwkt_reltoken(&tty_token);
903 lwkt_reltoken(&tty_token);
906 case CONS_SAVERSTART: /* immediately start/stop the screen saver */
908 * Note that this ioctl does not guarantee the screen saver
909 * actually starts or stops. It merely attempts to do so...
912 run_scrn_saver = (*(int *)data != 0);
914 sc->scrn_time_stamp -= scrn_blank_time;
916 lwkt_reltoken(&tty_token);
919 case CONS_SCRSHOT: /* get a screen shot */
921 scrshot_t *ptr = (scrshot_t*)data;
923 if (ISGRAPHSC(scp)) {
925 lwkt_reltoken(&tty_token);
928 if (scp->xsize != ptr->xsize || scp->ysize != ptr->ysize) {
930 lwkt_reltoken(&tty_token);
933 copyout ((void*)scp->vtb.vtb_buffer, ptr->buf,
934 ptr->xsize * ptr->ysize * sizeof(uint16_t));
936 lwkt_reltoken(&tty_token);
940 case VT_SETMODE: /* set screen switcher mode */
942 struct vt_mode *mode;
944 mode = (struct vt_mode *)data;
945 DPRINTF(5, ("sc%d: VT_SETMODE ", sc->unit));
946 if (scp->smode.mode == VT_PROCESS) {
947 lwkt_gettoken(&proc_token);
948 if (scp->proc == pfind(scp->pid) && scp->proc != curproc) {
949 DPRINTF(5, ("error EPERM\n"));
950 lwkt_reltoken(&proc_token);
951 lwkt_reltoken(&tty_token);
954 lwkt_reltoken(&proc_token);
957 if (mode->mode == VT_AUTO) {
958 scp->smode.mode = VT_AUTO;
961 DPRINTF(5, ("VT_AUTO, "));
962 if ((scp == sc->cur_scp) && (sc->unit == sc_console_unit))
963 cons_unavail = FALSE;
965 * note: must be called from a critical section because
966 * finish_vt_rel will call do_switch_scr which releases it
969 if (finish_vt_rel(scp, TRUE) == 0)
970 DPRINTF(5, ("reset WAIT_REL, "));
971 if (finish_vt_acq(scp) == 0)
972 DPRINTF(5, ("reset WAIT_ACQ, "));
974 if (!ISSIGVALID(mode->relsig) || !ISSIGVALID(mode->acqsig)
975 || !ISSIGVALID(mode->frsig)) {
977 DPRINTF(5, ("error EINVAL\n"));
978 lwkt_reltoken(&tty_token);
981 DPRINTF(5, ("VT_PROCESS %d, ", curproc->p_pid));
982 lwkt_gettoken(&proc_token);
983 bcopy(data, &scp->smode, sizeof(struct vt_mode));
985 scp->pid = scp->proc->p_pid;
986 lwkt_reltoken(&proc_token);
987 if ((scp == sc->cur_scp) && (sc->unit == sc_console_unit))
992 lwkt_reltoken(&tty_token);
996 case VT_GETMODE: /* get screen switcher mode */
997 bcopy(&scp->smode, data, sizeof(struct vt_mode));
998 lwkt_reltoken(&tty_token);
1001 case VT_RELDISP: /* screen switcher ioctl */
1004 * This must be the current vty which is in the VT_PROCESS
1007 if ((scp != sc->cur_scp) || (scp->smode.mode != VT_PROCESS)) {
1009 lwkt_reltoken(&tty_token);
1012 /* ...and this process is controlling it. */
1013 if (scp->proc != curproc) {
1015 lwkt_reltoken(&tty_token);
1019 switch(*(int *)data) {
1020 case VT_FALSE: /* user refuses to release screen, abort */
1022 * note: must be called from a critical section because
1023 * finish_vt_rel will call do_switch_scr which releases it
1026 if ((error = finish_vt_rel(scp, FALSE)) == 0)
1027 DPRINTF(5, ("sc%d: VT_FALSE\n", sc->unit));
1029 case VT_TRUE: /* user has released screen, go on */
1031 * note: must be called from a critical section because
1032 * finish_vt_rel will call do_switch_scr which releases it
1035 if ((error = finish_vt_rel(scp, TRUE)) == 0)
1036 DPRINTF(5, ("sc%d: VT_TRUE\n", sc->unit));
1038 case VT_ACKACQ: /* acquire acknowledged, switch completed */
1039 if ((error = finish_vt_acq(scp)) == 0)
1040 DPRINTF(5, ("sc%d: VT_ACKACQ\n", sc->unit));
1046 lwkt_reltoken(&tty_token);
1049 case VT_OPENQRY: /* return free virtual console */
1050 for (i = sc->first_vty; i < sc->first_vty + sc->vtys; i++) {
1051 tp = VIRTUAL_TTY(sc, i);
1052 if (!ISTTYOPEN(tp)) {
1053 *(int *)data = i + 1;
1054 lwkt_reltoken(&tty_token);
1058 lwkt_reltoken(&tty_token);
1061 case VT_ACTIVATE: /* switch to screen *data */
1062 i = (*(int *)data == 0) ? scp->index : (*(int *)data - 1);
1064 sc_clean_up(sc->cur_scp);
1066 lwkt_reltoken(&tty_token);
1067 return sc_switch_scr(sc, i);
1069 case VT_WAITACTIVE: /* wait for switch to occur */
1070 i = (*(int *)data == 0) ? scp->index : (*(int *)data - 1);
1071 if ((i < sc->first_vty) || (i >= sc->first_vty + sc->vtys)) {
1072 lwkt_reltoken(&tty_token);
1076 error = sc_clean_up(sc->cur_scp);
1079 lwkt_reltoken(&tty_token);
1082 scp = SC_STAT(SC_DEV(sc, i));
1083 if (scp == scp->sc->cur_scp) {
1084 lwkt_reltoken(&tty_token);
1087 error = tsleep((caddr_t)&scp->smode, PCATCH, "waitvt", 0);
1088 /* May return ERESTART */
1089 lwkt_reltoken(&tty_token);
1092 case VT_GETACTIVE: /* get active vty # */
1093 *(int *)data = sc->cur_scp->index + 1;
1094 lwkt_reltoken(&tty_token);
1097 case VT_GETINDEX: /* get this vty # */
1098 *(int *)data = scp->index + 1;
1099 lwkt_reltoken(&tty_token);
1102 case VT_LOCKSWITCH: /* prevent vty switching */
1103 if ((*(int *)data) & 0x01)
1104 sc->flags |= SC_SCRN_VTYLOCK;
1106 sc->flags &= ~SC_SCRN_VTYLOCK;
1107 lwkt_reltoken(&tty_token);
1110 case KDENABIO: /* allow io operations */
1111 error = priv_check_cred(ap->a_cred, PRIV_ROOT, 0);
1113 lwkt_reltoken(&tty_token);
1116 if (securelevel > 0) {
1117 lwkt_reltoken(&tty_token);
1120 lwkt_gettoken(&proc_token);
1121 #if defined(__i386__)
1122 curthread->td_lwp->lwp_md.md_regs->tf_eflags |= PSL_IOPL;
1123 #elif defined(__x86_64__)
1124 curthread->td_lwp->lwp_md.md_regs->tf_rflags |= PSL_IOPL;
1126 lwkt_reltoken(&proc_token);
1127 lwkt_reltoken(&tty_token);
1130 case KDDISABIO: /* disallow io operations (default) */
1131 lwkt_gettoken(&proc_token);
1132 #if defined(__i386__)
1133 curthread->td_lwp->lwp_md.md_regs->tf_eflags &= ~PSL_IOPL;
1134 #elif defined(__x86_64__)
1135 curthread->td_lwp->lwp_md.md_regs->tf_rflags &= ~PSL_IOPL;
1137 lwkt_reltoken(&proc_token);
1138 lwkt_reltoken(&tty_token);
1141 case KDSKBSTATE: /* set keyboard state (locks) */
1142 if (*(int *)data & ~LOCK_MASK) {
1143 lwkt_reltoken(&tty_token);
1146 scp->status &= ~LOCK_MASK;
1147 scp->status |= *(int *)data;
1148 if (scp == sc->cur_scp)
1149 update_kbd_state(scp, scp->status, LOCK_MASK);
1150 lwkt_reltoken(&tty_token);
1153 case KDGKBSTATE: /* get keyboard state (locks) */
1154 if (scp == sc->cur_scp)
1155 save_kbd_state(scp);
1156 *(int *)data = scp->status & LOCK_MASK;
1157 lwkt_reltoken(&tty_token);
1160 case KDGETREPEAT: /* get keyboard repeat & delay rates */
1161 case KDSETREPEAT: /* set keyboard repeat & delay rates (new) */
1162 error = kbd_ioctl(sc->kbd, cmd, data);
1163 if (error == ENOIOCTL)
1165 lwkt_reltoken(&tty_token);
1168 case KDSETRAD: /* set keyboard repeat & delay rates (old) */
1169 if (*(int *)data & ~0x7f) {
1170 lwkt_reltoken(&tty_token);
1173 error = kbd_ioctl(sc->kbd, cmd, data);
1174 if (error == ENOIOCTL)
1176 lwkt_reltoken(&tty_token);
1179 case KDSKBMODE: /* set keyboard mode */
1180 switch (*(int *)data) {
1181 case K_XLATE: /* switch to XLT ascii mode */
1182 case K_RAW: /* switch to RAW scancode mode */
1183 case K_CODE: /* switch to CODE mode */
1184 scp->kbd_mode = *(int *)data;
1185 if (scp == sc->cur_scp)
1186 kbd_ioctl(sc->kbd, cmd, data);
1187 lwkt_reltoken(&tty_token);
1190 lwkt_reltoken(&tty_token);
1195 case KDGKBMODE: /* get keyboard mode */
1196 *(int *)data = scp->kbd_mode;
1197 lwkt_reltoken(&tty_token);
1201 error = kbd_ioctl(sc->kbd, cmd, data);
1202 if (error == ENOIOCTL)
1204 lwkt_reltoken(&tty_token);
1207 case KDMKTONE: /* sound the bell */
1209 sc_bell(scp, (*(int*)data)&0xffff,
1210 (((*(int*)data)>>16)&0xffff)*hz/1000);
1212 sc_bell(scp, scp->bell_pitch, scp->bell_duration);
1213 lwkt_reltoken(&tty_token);
1216 case KIOCSOUND: /* make tone (*data) hz */
1217 if (scp == sc->cur_scp) {
1219 lwkt_reltoken(&tty_token);
1220 return sc_tone(*(int *)data);
1222 lwkt_reltoken(&tty_token);
1226 lwkt_reltoken(&tty_token);
1229 case KDGKBTYPE: /* get keyboard type */
1230 error = kbd_ioctl(sc->kbd, cmd, data);
1231 if (error == ENOIOCTL) {
1232 /* always return something? XXX */
1235 lwkt_reltoken(&tty_token);
1238 case KDSETLED: /* set keyboard LED status */
1239 if (*(int *)data & ~LED_MASK) { /* FIXME: LOCK_MASK? */
1240 lwkt_reltoken(&tty_token);
1243 scp->status &= ~LED_MASK;
1244 scp->status |= *(int *)data;
1245 if (scp == sc->cur_scp)
1246 update_kbd_leds(scp, scp->status);
1247 lwkt_reltoken(&tty_token);
1250 case KDGETLED: /* get keyboard LED status */
1251 if (scp == sc->cur_scp)
1252 save_kbd_state(scp);
1253 *(int *)data = scp->status & LED_MASK;
1254 lwkt_reltoken(&tty_token);
1257 case KBADDKBD: /* add/remove keyboard to/from mux */
1259 error = kbd_ioctl(sc->kbd, cmd, data);
1260 if (error == ENOIOCTL)
1262 lwkt_reltoken(&tty_token);
1265 case CONS_SETKBD: /* set the new keyboard */
1270 newkbd = kbd_get_keyboard(*(int *)data);
1271 if (newkbd == NULL) {
1273 lwkt_reltoken(&tty_token);
1277 if (sc->kbd != newkbd) {
1278 i = kbd_allocate(newkbd->kb_name, newkbd->kb_unit,
1279 (void *)&sc->keyboard, sckbdevent, sc);
1280 /* i == newkbd->kb_index */
1282 if (sc->kbd != NULL) {
1283 save_kbd_state(sc->cur_scp);
1284 kbd_release(sc->kbd, (void *)&sc->keyboard);
1286 sc->kbd = kbd_get_keyboard(i); /* sc->kbd == newkbd */
1288 kbd_ioctl(sc->kbd, KDSKBMODE,
1289 (caddr_t)&sc->cur_scp->kbd_mode);
1290 update_kbd_state(sc->cur_scp, sc->cur_scp->status,
1293 error = EPERM; /* XXX */
1297 lwkt_reltoken(&tty_token);
1301 case CONS_RELKBD: /* release the current keyboard */
1304 if (sc->kbd != NULL) {
1305 save_kbd_state(sc->cur_scp);
1306 error = kbd_release(sc->kbd, (void *)&sc->keyboard);
1313 lwkt_reltoken(&tty_token);
1316 case CONS_GETTERM: /* get the current terminal emulator info */
1320 if (((term_info_t *)data)->ti_index == 0) {
1323 sw = sc_term_match_by_number(((term_info_t *)data)->ti_index);
1326 strncpy(((term_info_t *)data)->ti_name, sw->te_name,
1327 sizeof(((term_info_t *)data)->ti_name));
1328 strncpy(((term_info_t *)data)->ti_desc, sw->te_desc,
1329 sizeof(((term_info_t *)data)->ti_desc));
1330 ((term_info_t *)data)->ti_flags = 0;
1331 lwkt_reltoken(&tty_token);
1334 ((term_info_t *)data)->ti_name[0] = '\0';
1335 ((term_info_t *)data)->ti_desc[0] = '\0';
1336 ((term_info_t *)data)->ti_flags = 0;
1337 lwkt_reltoken(&tty_token);
1342 case CONS_SETTERM: /* set the current terminal emulator */
1344 error = sc_init_emulator(scp, ((term_info_t *)data)->ti_name);
1345 /* FIXME: what if scp == sc_console! XXX */
1347 lwkt_reltoken(&tty_token);
1350 case GIO_SCRNMAP: /* get output translation table */
1351 bcopy(&sc->scr_map, data, sizeof(sc->scr_map));
1352 lwkt_reltoken(&tty_token);
1355 case PIO_SCRNMAP: /* set output translation table */
1356 bcopy(data, &sc->scr_map, sizeof(sc->scr_map));
1357 for (i=0; i<sizeof(sc->scr_map); i++) {
1358 sc->scr_rmap[sc->scr_map[i]] = i;
1360 lwkt_reltoken(&tty_token);
1363 case GIO_KEYMAP: /* get keyboard translation table */
1364 case PIO_KEYMAP: /* set keyboard translation table */
1365 case GIO_DEADKEYMAP: /* get accent key translation table */
1366 case PIO_DEADKEYMAP: /* set accent key translation table */
1367 case GETFKEY: /* get function key string */
1368 case SETFKEY: /* set function key string */
1369 error = kbd_ioctl(sc->kbd, cmd, data);
1370 if (error == ENOIOCTL)
1372 lwkt_reltoken(&tty_token);
1375 #ifndef SC_NO_FONT_LOADING
1377 case PIO_FONT8x8: /* set 8x8 dot font */
1378 if (!ISFONTAVAIL(sc->adp->va_flags)) {
1379 lwkt_reltoken(&tty_token);
1382 bcopy(data, sc->font_8, 8*256);
1383 sc->fonts_loaded |= FONT_8;
1386 * Always use the font page #0. XXX
1387 * Don't load if the current font size is not 8x8.
1389 if (ISTEXTSC(sc->cur_scp) && (sc->cur_scp->font_size < 14))
1390 sc_load_font(sc->cur_scp, 0, 8, sc->font_8, 0, 256);
1391 lwkt_reltoken(&tty_token);
1394 case GIO_FONT8x8: /* get 8x8 dot font */
1395 if (!ISFONTAVAIL(sc->adp->va_flags)) {
1396 lwkt_reltoken(&tty_token);
1399 if (sc->fonts_loaded & FONT_8) {
1400 bcopy(sc->font_8, data, 8*256);
1401 lwkt_reltoken(&tty_token);
1405 lwkt_reltoken(&tty_token);
1409 case PIO_FONT8x14: /* set 8x14 dot font */
1410 if (!ISFONTAVAIL(sc->adp->va_flags)) {
1411 lwkt_reltoken(&tty_token);
1414 bcopy(data, sc->font_14, 14*256);
1415 sc->fonts_loaded |= FONT_14;
1418 * Always use the font page #0. XXX
1419 * Don't load if the current font size is not 8x14.
1421 if (ISTEXTSC(sc->cur_scp)
1422 && (sc->cur_scp->font_size >= 14)
1423 && (sc->cur_scp->font_size < 16))
1424 sc_load_font(sc->cur_scp, 0, 14, sc->font_14, 0, 256);
1425 lwkt_reltoken(&tty_token);
1428 case GIO_FONT8x14: /* get 8x14 dot font */
1429 if (!ISFONTAVAIL(sc->adp->va_flags)) {
1430 lwkt_reltoken(&tty_token);
1433 if (sc->fonts_loaded & FONT_14) {
1434 bcopy(sc->font_14, data, 14*256);
1435 lwkt_reltoken(&tty_token);
1439 lwkt_reltoken(&tty_token);
1443 case PIO_FONT8x16: /* set 8x16 dot font */
1444 if (!ISFONTAVAIL(sc->adp->va_flags)) {
1445 lwkt_reltoken(&tty_token);
1448 bcopy(data, sc->font_16, 16*256);
1449 sc->fonts_loaded |= FONT_16;
1452 * Always use the font page #0. XXX
1453 * Don't load if the current font size is not 8x16.
1455 if (ISTEXTSC(sc->cur_scp) && (sc->cur_scp->font_size >= 16))
1456 sc_load_font(sc->cur_scp, 0, 16, sc->font_16, 0, 256);
1457 lwkt_reltoken(&tty_token);
1460 case GIO_FONT8x16: /* get 8x16 dot font */
1461 if (!ISFONTAVAIL(sc->adp->va_flags)) {
1462 lwkt_reltoken(&tty_token);
1465 if (sc->fonts_loaded & FONT_16) {
1466 bcopy(sc->font_16, data, 16*256);
1467 lwkt_reltoken(&tty_token);
1471 lwkt_reltoken(&tty_token);
1475 #endif /* SC_NO_FONT_LOADING */
1481 error = (*linesw[tp->t_line].l_ioctl)(tp, cmd, data, flag, ap->a_cred);
1482 if (error != ENOIOCTL) {
1483 lwkt_reltoken(&tty_token);
1486 error = ttioctl(tp, cmd, data, flag);
1487 if (error != ENOIOCTL) {
1488 lwkt_reltoken(&tty_token);
1491 lwkt_reltoken(&tty_token);
1496 scstart(struct tty *tp)
1500 u_char buf[PCBURST];
1501 scr_stat *scp = SC_STAT(tp->t_dev);
1504 if (scp->status & SLKED ||
1505 (scp == scp->sc->cur_scp && scp->sc->blink_in_progress))
1510 if (!(tp->t_state & (TS_TIMEOUT | TS_BUSY | TS_TTSTOP))) {
1511 tp->t_state |= TS_BUSY;
1514 len = q_to_b(rbp, buf, PCBURST);
1515 sc_puts(scp, buf, len);
1517 tp->t_state &= ~TS_BUSY;
1526 sccnprobe(struct consdev *cp)
1531 cp->cn_pri = sc_get_cons_priority(&unit, &flags);
1533 /* a video card is always required */
1534 if (!scvidprobe(unit, flags, TRUE))
1535 cp->cn_pri = CN_DEAD;
1537 /* syscons will become console even when there is no keyboard */
1538 sckbdprobe(unit, flags, TRUE);
1540 if (cp->cn_pri == CN_DEAD) {
1544 /* initialize required fields */
1545 cp->cn_probegood = 1;
1549 sccninit(struct consdev *cp)
1554 sc_get_cons_priority(&unit, &flags);
1555 scinit(unit, flags | SC_KERNEL_CONSOLE);
1556 sc_console_unit = unit;
1557 sc_console = sc_get_softc(unit, SC_KERNEL_CONSOLE)->console_scp;
1561 sccninit_fini(struct consdev *cp)
1563 if (cctl_dev == NULL)
1564 kprintf("sccninit_fini: WARNING: cctl_dev is NULL!\n");
1565 cp->cn_dev = cctl_dev;
1569 sccnterm(struct consdev *cp)
1571 /* we are not the kernel console any more, release everything */
1573 if (sc_console_unit < 0)
1574 return; /* shouldn't happen */
1577 sc_clear_screen(sc_console);
1578 sccnupdate(sc_console);
1580 scterm(sc_console_unit, SC_KERNEL_CONSOLE);
1581 sc_console_unit = -1;
1586 * Console path - cannot block!
1589 sccnputc(void *private, int c)
1592 scr_stat *scp = sc_console;
1594 #ifndef SC_NO_HISTORY
1596 #endif /* !SC_NO_HISTORY */
1598 /* assert(sc_console != NULL) */
1601 #ifndef SC_NO_HISTORY
1602 if (scp == scp->sc->cur_scp && scp->status & SLKED) {
1603 scp->status &= ~SLKED;
1604 update_kbd_state(scp, scp->status, SLKED);
1605 if (scp->status & BUFFER_SAVED) {
1606 if (!sc_hist_restore(scp))
1607 sc_remove_cutmarking(scp);
1608 scp->status &= ~BUFFER_SAVED;
1609 scp->status |= CURSOR_ENABLED;
1610 sc_draw_cursor_image(scp);
1612 tp = VIRTUAL_TTY(scp->sc, scp->index);
1613 if (ISTTYOPEN(tp)) {
1619 #endif /* !SC_NO_HISTORY */
1622 if (kernel_console_ts != NULL)
1623 scp->ts = kernel_console_ts;
1625 sc_puts(scp, buf, 1);
1633 * Console path - cannot block!
1636 sccngetc(void *private)
1638 return sccngetch(0);
1642 * Console path - cannot block!
1645 sccncheckc(void *private)
1647 return sccngetch(SCGETC_NONBLOCK);
1651 sccndbctl(void *private, int on)
1653 /* assert(sc_console_unit >= 0) */
1654 /* try to switch to the kernel console screen */
1655 if (on && debugger == 0) {
1657 * TRY to make sure the screen saver is stopped,
1658 * and the screen is updated before switching to
1663 && sc_console->sc->cur_scp->smode.mode == VT_AUTO
1664 && sc_console->smode.mode == VT_AUTO) {
1665 sc_console->sc->cur_scp->status |= MOUSE_HIDDEN;
1666 sc_switch_scr(sc_console->sc, sc_console->index);
1676 * Console path - cannot block!
1679 sccngetch(int flags)
1681 static struct fkeytab fkey;
1689 /* assert(sc_console != NULL) */
1692 * Stop the screen saver and update the screen if necessary.
1693 * What if we have been running in the screen saver code... XXX
1695 sc_touch_scrn_saver();
1696 scp = sc_console->sc->cur_scp; /* XXX */
1700 if (fkeycp < fkey.len) {
1701 return fkey.str[fkeycp++];
1704 if (scp->sc->kbd == NULL) {
1709 * Make sure the keyboard is accessible even when the kbd device
1710 * driver is disabled.
1713 kbd_enable(scp->sc->kbd);
1715 /* we shall always use the keyboard in the XLATE mode here */
1716 cur_mode = scp->kbd_mode;
1717 scp->kbd_mode = K_XLATE;
1718 kbd_ioctl(scp->sc->kbd, KDSKBMODE, (caddr_t)&scp->kbd_mode);
1720 kbd_poll(scp->sc->kbd, TRUE);
1721 c = scgetc(scp->sc, SCGETC_CN | flags);
1722 kbd_poll(scp->sc->kbd, FALSE);
1724 scp->kbd_mode = cur_mode;
1725 kbd_ioctl(scp->sc->kbd, KDSKBMODE, (caddr_t)&scp->kbd_mode);
1726 kbd_disable(scp->sc->kbd);
1729 switch (KEYFLAGS(c)) {
1730 case 0: /* normal char */
1732 case FKEY: /* function key */
1733 p = kbd_get_fkeystr(scp->sc->kbd, KEYCHAR(c), (size_t *)&fkeycp);
1735 if ((p != NULL) && (fkey.len > 0)) {
1736 bcopy(p, fkey.str, fkey.len);
1750 sccnupdate(scr_stat *scp)
1752 /* this is a cut-down version of scrn_timer()... */
1754 if (scp->sc->font_loading_in_progress || scp->sc->videoio_in_progress) {
1758 if (debugger > 0 || panicstr || shutdown_in_progress) {
1759 sc_touch_scrn_saver();
1760 } else if (scp != scp->sc->cur_scp) {
1764 if (!run_scrn_saver)
1765 scp->sc->flags &= ~SC_SCRN_IDLE;
1767 if ((saver_mode != CONS_LKM_SAVER) || !(scp->sc->flags & SC_SCRN_IDLE))
1768 if (scp->sc->flags & SC_SCRN_BLANKED)
1769 stop_scrn_saver(scp->sc, current_saver);
1770 #endif /* NSPLASH */
1772 if (scp != scp->sc->cur_scp || scp->sc->blink_in_progress
1773 || scp->sc->switch_in_progress) {
1777 * FIXME: unlike scrn_timer(), we call scrn_update() from here even
1778 * when write_in_progress is non-zero. XXX
1781 if (!ISGRAPHSC(scp) && !(scp->sc->flags & SC_SCRN_BLANKED))
1782 scrn_update(scp, TRUE);
1786 scrn_timer(void *arg)
1788 static int kbd_interval = 0;
1795 * Setup depending on who called us
1797 again = (arg != NULL);
1799 sc = (sc_softc_t *)arg;
1800 } else if (sc_console != NULL) {
1801 sc = sc_console->sc;
1807 * Don't do anything when we are performing some I/O operations.
1808 * (These are initiated by the frontend?)
1810 if (sc->font_loading_in_progress || sc->videoio_in_progress) {
1812 callout_reset(&sc->scrn_timer_ch, hz / 10, scrn_timer, sc);
1817 * Try to allocate a keyboard automatically
1819 if ((sc->kbd == NULL) && (sc->config & SC_AUTODETECT_KBD)) {
1820 if (++kbd_interval >= 25) {
1821 sc->keyboard = sc_allocate_keyboard(sc, -1);
1822 if (sc->keyboard >= 0) {
1823 sc->kbd = kbd_get_keyboard(sc->keyboard);
1824 kbd_ioctl(sc->kbd, KDSKBMODE,
1825 (caddr_t)&sc->cur_scp->kbd_mode);
1826 update_kbd_state(sc->cur_scp, sc->cur_scp->status,
1834 * Should we stop the screen saver? We need the syscons_lock
1835 * for most of this stuff.
1837 getmicrouptime(&tv);
1839 if (syscons_lock_nonblock() == 0) {
1841 callout_reset(&sc->scrn_timer_ch, hz / 10, scrn_timer, sc);
1845 if (debugger > 0 || panicstr || shutdown_in_progress)
1846 sc_touch_scrn_saver();
1847 if (run_scrn_saver) {
1848 if (tv.tv_sec > sc->scrn_time_stamp + scrn_blank_time)
1849 sc->flags |= SC_SCRN_IDLE;
1851 sc->flags &= ~SC_SCRN_IDLE;
1853 sc->scrn_time_stamp = tv.tv_sec;
1854 sc->flags &= ~SC_SCRN_IDLE;
1855 if (scrn_blank_time > 0)
1856 run_scrn_saver = TRUE;
1859 if ((saver_mode != CONS_LKM_SAVER) || !(sc->flags & SC_SCRN_IDLE))
1860 if (sc->flags & SC_SCRN_BLANKED)
1861 stop_scrn_saver(sc, current_saver);
1862 #endif /* NSPLASH */
1864 /* should we just return ? */
1865 if (sc->blink_in_progress || sc->switch_in_progress ||
1866 sc->write_in_progress)
1870 callout_reset(&sc->scrn_timer_ch, hz / 10, scrn_timer, sc);
1874 /* Update the screen */
1875 scp = sc->cur_scp; /* cur_scp may have changed... */
1876 if (!ISGRAPHSC(scp) && !(sc->flags & SC_SCRN_BLANKED))
1877 scrn_update(scp, TRUE);
1880 /* should we activate the screen saver? */
1881 if ((saver_mode == CONS_LKM_SAVER) && (sc->flags & SC_SCRN_IDLE))
1882 if (!ISGRAPHSC(scp) || (sc->flags & SC_SCRN_BLANKED))
1883 (*current_saver)(sc, TRUE);
1884 #endif /* NSPLASH */
1888 callout_reset(&sc->scrn_timer_ch, hz / 25, scrn_timer, sc);
1892 and_region(int *s1, int *e1, int s2, int e2)
1894 if (*e1 < s2 || e2 < *s1)
1896 *s1 = imax(*s1, s2);
1897 *e1 = imin(*e1, e2);
1902 scrn_update(scr_stat *scp, int show_cursor)
1909 /* assert(scp == scp->sc->cur_scp) */
1911 ++scp->sc->videoio_in_progress;
1913 #ifndef SC_NO_CUTPASTE
1914 /* remove the previous mouse pointer image if necessary */
1915 if (scp->status & MOUSE_VISIBLE) {
1917 e = scp->mouse_pos + scp->xsize + 1;
1918 if ((scp->status & (MOUSE_MOVED | MOUSE_HIDDEN))
1919 || and_region(&s, &e, scp->start, scp->end)
1920 || ((scp->status & CURSOR_ENABLED) &&
1921 (scp->cursor_pos != scp->cursor_oldpos) &&
1922 (and_region(&s, &e, scp->cursor_pos, scp->cursor_pos)
1923 || and_region(&s, &e, scp->cursor_oldpos, scp->cursor_oldpos)))) {
1924 sc_remove_mouse_image(scp);
1925 if (scp->end >= scp->xsize*scp->ysize)
1926 scp->end = scp->xsize*scp->ysize - 1;
1929 #endif /* !SC_NO_CUTPASTE */
1933 if (scp->end >= scp->xsize*scp->ysize) {
1934 kprintf("scrn_update(): scp->end %d > size_of_screen!!\n", scp->end);
1935 scp->end = scp->xsize*scp->ysize - 1;
1937 if (scp->start < 0) {
1938 kprintf("scrn_update(): scp->start %d < 0\n", scp->start);
1943 /* update screen image */
1944 if (scp->start <= scp->end) {
1945 if (scp->mouse_cut_end >= 0) {
1946 /* there is a marked region for cut & paste */
1947 if (scp->mouse_cut_start <= scp->mouse_cut_end) {
1948 start = scp->mouse_cut_start;
1949 end = scp->mouse_cut_end;
1951 start = scp->mouse_cut_end;
1952 end = scp->mouse_cut_start - 1;
1956 /* does the cut-mark region overlap with the update region? */
1957 if (and_region(&s, &e, scp->start, scp->end)) {
1958 (*scp->rndr->draw)(scp, s, e - s + 1, TRUE);
1961 if (and_region(&s, &e, scp->start, scp->end))
1962 (*scp->rndr->draw)(scp, s, e - s + 1, FALSE);
1964 e = scp->xsize*scp->ysize - 1;
1965 if (and_region(&s, &e, scp->start, scp->end))
1966 (*scp->rndr->draw)(scp, s, e - s + 1, FALSE);
1968 (*scp->rndr->draw)(scp, scp->start,
1969 scp->end - scp->start + 1, FALSE);
1972 (*scp->rndr->draw)(scp, scp->start,
1973 scp->end - scp->start + 1, FALSE);
1977 /* we are not to show the cursor and the mouse pointer... */
1980 scp->start = scp->xsize*scp->ysize - 1;
1981 --scp->sc->videoio_in_progress;
1985 /* update cursor image */
1986 if (scp->status & CURSOR_ENABLED) {
1989 /* did cursor move since last time ? */
1990 if (scp->cursor_pos != scp->cursor_oldpos) {
1991 /* do we need to remove old cursor image ? */
1992 if (!and_region(&s, &e, scp->cursor_oldpos, scp->cursor_oldpos))
1993 sc_remove_cursor_image(scp);
1994 sc_draw_cursor_image(scp);
1996 if (and_region(&s, &e, scp->cursor_pos, scp->cursor_pos))
1997 /* cursor didn't move, but has been overwritten */
1998 sc_draw_cursor_image(scp);
1999 else if (scp->sc->flags & SC_BLINK_CURSOR)
2000 /* if it's a blinking cursor, update it */
2001 (*scp->rndr->blink_cursor)(scp, scp->cursor_pos,
2002 sc_inside_cutmark(scp,
2007 #ifndef SC_NO_CUTPASTE
2008 /* update "pseudo" mouse pointer image */
2009 if (scp->sc->flags & SC_MOUSE_ENABLED) {
2010 if (!(scp->status & (MOUSE_VISIBLE | MOUSE_HIDDEN))) {
2011 scp->status &= ~MOUSE_MOVED;
2012 sc_draw_mouse_image(scp);
2015 #endif /* SC_NO_CUTPASTE */
2018 scp->start = scp->xsize*scp->ysize - 1;
2020 --scp->sc->videoio_in_progress;
2025 scsplash_callback(int event, void *arg)
2030 sc = (sc_softc_t *)arg;
2034 if (add_scrn_saver(scsplash_saver) == 0) {
2035 sc->flags &= ~SC_SAVER_FAILED;
2036 run_scrn_saver = TRUE;
2037 if (cold && !(boothowto & (RB_VERBOSE | RB_CONFIG))) {
2038 scsplash_stick(TRUE);
2039 (*current_saver)(sc, TRUE);
2045 if (current_saver == scsplash_saver) {
2046 scsplash_stick(FALSE);
2047 error = remove_scrn_saver(scsplash_saver);
2060 scsplash_saver(sc_softc_t *sc, int show)
2062 static int busy = FALSE;
2071 if (!(sc->flags & SC_SAVER_FAILED)) {
2072 if (!(sc->flags & SC_SCRN_BLANKED))
2073 set_scrn_saver_mode(scp, -1, NULL, 0);
2074 switch (splash(sc->adp, TRUE)) {
2075 case 0: /* succeeded */
2077 case EAGAIN: /* try later */
2078 restore_scrn_saver_mode(scp, FALSE);
2079 sc_touch_scrn_saver(); /* XXX */
2082 sc->flags |= SC_SAVER_FAILED;
2083 scsplash_stick(FALSE);
2084 restore_scrn_saver_mode(scp, TRUE);
2085 kprintf("scsplash_saver(): failed to put up the image\n");
2089 } else if (!sticky_splash) {
2090 if ((sc->flags & SC_SCRN_BLANKED) && (splash(sc->adp, FALSE) == 0))
2091 restore_scrn_saver_mode(scp, TRUE);
2097 add_scrn_saver(void (*this_saver)(sc_softc_t *, int))
2102 if (current_saver != none_saver) {
2103 error = remove_scrn_saver(current_saver);
2108 if (current_saver != none_saver) {
2112 run_scrn_saver = FALSE;
2113 saver_mode = CONS_LKM_SAVER;
2114 current_saver = this_saver;
2119 remove_scrn_saver(void (*this_saver)(sc_softc_t *, int))
2121 if (current_saver != this_saver)
2126 * In order to prevent `current_saver' from being called by
2127 * the timeout routine `scrn_timer()' while we manipulate
2128 * the saver list, we shall set `current_saver' to `none_saver'
2129 * before stopping the current saver, rather than blocking by `splXX()'.
2131 current_saver = none_saver;
2133 stop_scrn_saver(this_saver);
2135 /* unblank all blanked screens */
2136 wait_scrn_saver_stop(NULL);
2141 current_saver = none_saver;
2146 set_scrn_saver_mode(scr_stat *scp, int mode, u_char *pal, int border)
2149 /* assert(scp == scp->sc->cur_scp) */
2151 if (!ISGRAPHSC(scp))
2152 sc_remove_cursor_image(scp);
2153 scp->splash_save_mode = scp->mode;
2154 scp->splash_save_status = scp->status & (GRAPHICS_MODE | PIXEL_MODE);
2155 scp->status &= ~(GRAPHICS_MODE | PIXEL_MODE);
2156 scp->status |= (UNKNOWN_MODE | SAVER_RUNNING);
2157 scp->sc->flags |= SC_SCRN_BLANKED;
2164 if (set_mode(scp) == 0) {
2165 if (scp->sc->adp->va_info.vi_flags & V_INFO_GRAPHICS)
2166 scp->status |= GRAPHICS_MODE;
2167 #ifndef SC_NO_PALETTE_LOADING
2169 load_palette(scp->sc->adp, pal);
2171 sc_set_border(scp, border);
2175 scp->mode = scp->splash_save_mode;
2176 scp->status &= ~(UNKNOWN_MODE | SAVER_RUNNING);
2177 scp->status |= scp->splash_save_status;
2185 restore_scrn_saver_mode(scr_stat *scp, int changemode)
2190 /* assert(scp == scp->sc->cur_scp) */
2193 status = scp->status;
2194 scp->mode = scp->splash_save_mode;
2195 scp->status &= ~(UNKNOWN_MODE | SAVER_RUNNING);
2196 scp->status |= scp->splash_save_status;
2197 scp->sc->flags &= ~SC_SCRN_BLANKED;
2199 if (!ISGRAPHSC(scp))
2200 sc_draw_cursor_image(scp);
2205 if (set_mode(scp) == 0) {
2206 #ifndef SC_NO_PALETTE_LOADING
2207 load_palette(scp->sc->adp, scp->sc->palette);
2214 scp->status = status;
2222 stop_scrn_saver(sc_softc_t *sc, void (*saver)(sc_softc_t *, int))
2224 (*saver)(sc, FALSE);
2225 run_scrn_saver = FALSE;
2226 /* the screen saver may have chosen not to stop after all... */
2227 if (sc->flags & SC_SCRN_BLANKED) {
2231 mark_all(sc->cur_scp);
2232 if (sc->delayed_next_scr)
2233 sc_switch_scr(sc, sc->delayed_next_scr - 1);
2234 wakeup((caddr_t)&scrn_blanked);
2238 wait_scrn_saver_stop(sc_softc_t *sc)
2242 while (scrn_blanked > 0) {
2243 run_scrn_saver = FALSE;
2244 if (sc && !(sc->flags & SC_SCRN_BLANKED)) {
2248 error = tsleep((caddr_t)&scrn_blanked, PCATCH, "scrsav", 0);
2249 /* May return ERESTART */
2253 run_scrn_saver = FALSE;
2256 #endif /* NSPLASH */
2259 sc_touch_scrn_saver(void)
2261 scsplash_stick(FALSE);
2262 run_scrn_saver = FALSE;
2266 sc_switch_scr(sc_softc_t *sc, u_int next_scr)
2271 DPRINTF(5, ("sc0: sc_switch_scr() %d ", next_scr + 1));
2273 lwkt_gettoken(&tty_token);
2274 /* prevent switch if previously requested */
2275 if (sc->flags & SC_SCRN_VTYLOCK) {
2276 sc_bell(sc->cur_scp, sc->cur_scp->bell_pitch,
2277 sc->cur_scp->bell_duration);
2278 lwkt_reltoken(&tty_token);
2282 /* delay switch if the screen is blanked or being updated */
2283 if ((sc->flags & SC_SCRN_BLANKED) || sc->write_in_progress
2284 || sc->blink_in_progress || sc->videoio_in_progress) {
2285 sc->delayed_next_scr = next_scr + 1;
2286 sc_touch_scrn_saver();
2287 DPRINTF(5, ("switch delayed\n"));
2288 lwkt_reltoken(&tty_token);
2293 cur_scp = sc->cur_scp;
2295 /* we are in the middle of the vty switching process... */
2296 lwkt_gettoken(&proc_token);
2297 if (sc->switch_in_progress
2298 && (cur_scp->smode.mode == VT_PROCESS)
2300 if (cur_scp->proc != pfind(cur_scp->pid)) {
2302 * The controlling process has died!!. Do some clean up.
2303 * NOTE:`cur_scp->proc' and `cur_scp->smode.mode'
2304 * are not reset here yet; they will be cleared later.
2306 DPRINTF(5, ("cur_scp controlling process %d died, ",
2308 if (cur_scp->status & SWITCH_WAIT_REL) {
2310 * Force the previous switch to finish, but return now
2313 * note: must be called from a critical section because
2314 * finish_vt_rel will call do_switch_scr which releases it
2317 DPRINTF(5, ("reset WAIT_REL, "));
2318 finish_vt_rel(cur_scp, TRUE);
2320 DPRINTF(5, ("finishing previous switch\n"));
2321 lwkt_reltoken(&proc_token);
2322 lwkt_reltoken(&tty_token);
2324 } else if (cur_scp->status & SWITCH_WAIT_ACQ) {
2325 /* let's assume screen switch has been completed. */
2326 DPRINTF(5, ("reset WAIT_ACQ, "));
2327 finish_vt_acq(cur_scp);
2330 * We are in between screen release and acquisition, and
2331 * reached here via scgetc() or scrn_timer() which has
2332 * interrupted exchange_scr(). Don't do anything stupid.
2334 DPRINTF(5, ("waiting nothing, "));
2338 * The controlling process is alive, but not responding...
2339 * It is either buggy or it may be just taking time.
2340 * The following code is a gross kludge to cope with this
2341 * problem for which there is no clean solution. XXX
2343 if (cur_scp->status & SWITCH_WAIT_REL) {
2344 switch (sc->switch_in_progress++) {
2348 DPRINTF(5, ("sending relsig again, "));
2349 signal_vt_rel(cur_scp);
2356 * Act as if the controlling program returned
2359 * note: must be called from a critical section because
2360 * finish_vt_rel will call do_switch_scr which releases it
2363 DPRINTF(5, ("force reset WAIT_REL, "));
2364 finish_vt_rel(cur_scp, FALSE);
2366 DPRINTF(5, ("act as if VT_FALSE was seen\n"));
2367 lwkt_reltoken(&proc_token);
2368 lwkt_reltoken(&tty_token);
2371 } else if (cur_scp->status & SWITCH_WAIT_ACQ) {
2372 switch (sc->switch_in_progress++) {
2376 DPRINTF(5, ("sending acqsig again, "));
2377 signal_vt_acq(cur_scp);
2383 /* clear the flag and finish the previous switch */
2384 DPRINTF(5, ("force reset WAIT_ACQ, "));
2385 finish_vt_acq(cur_scp);
2391 lwkt_reltoken(&proc_token);
2394 * Return error if an invalid argument is given, or vty switch
2395 * is still in progress.
2397 if ((next_scr < sc->first_vty) || (next_scr >= sc->first_vty + sc->vtys)
2398 || sc->switch_in_progress) {
2400 sc_bell(cur_scp, bios_value.bell_pitch, BELL_DURATION);
2401 DPRINTF(5, ("error 1\n"));
2402 lwkt_reltoken(&tty_token);
2407 * Don't allow switching away from the graphics mode vty
2408 * if the switch mode is VT_AUTO, unless the next vty is the same
2409 * as the current or the current vty has been closed (but showing).
2411 tp = VIRTUAL_TTY(sc, cur_scp->index);
2412 if ((cur_scp->index != next_scr)
2414 && (cur_scp->smode.mode == VT_AUTO)
2415 && ISGRAPHSC(cur_scp)) {
2417 sc_bell(cur_scp, bios_value.bell_pitch, BELL_DURATION);
2418 DPRINTF(5, ("error, graphics mode\n"));
2419 lwkt_reltoken(&tty_token);
2424 * Is the wanted vty open? Don't allow switching to a closed vty.
2425 * If we are in DDB, don't switch to a vty in the VT_PROCESS mode.
2426 * Note that we always allow the user to switch to the kernel
2427 * console even if it is closed.
2429 if ((sc_console == NULL) || (next_scr != sc_console->index)) {
2430 tp = VIRTUAL_TTY(sc, next_scr);
2431 if (!ISTTYOPEN(tp)) {
2433 sc_bell(cur_scp, bios_value.bell_pitch, BELL_DURATION);
2434 DPRINTF(5, ("error 2, requested vty isn't open!\n"));
2435 lwkt_reltoken(&tty_token);
2438 if ((debugger > 0) && (SC_STAT(tp->t_dev)->smode.mode == VT_PROCESS)) {
2440 DPRINTF(5, ("error 3, requested vty is in the VT_PROCESS mode\n"));
2441 lwkt_reltoken(&tty_token);
2446 /* this is the start of vty switching process... */
2447 ++sc->switch_in_progress;
2448 sc->delayed_next_scr = 0;
2449 sc->old_scp = cur_scp;
2450 sc->new_scp = SC_STAT(SC_DEV(sc, next_scr));
2451 if (sc->new_scp == sc->old_scp) {
2452 sc->switch_in_progress = 0;
2453 wakeup((caddr_t)&sc->new_scp->smode);
2455 DPRINTF(5, ("switch done (new == old)\n"));
2456 lwkt_reltoken(&tty_token);
2460 /* has controlling process died? */
2461 vt_proc_alive(sc->old_scp);
2462 vt_proc_alive(sc->new_scp);
2464 /* wait for the controlling process to release the screen, if necessary */
2465 if (signal_vt_rel(sc->old_scp)) {
2467 lwkt_reltoken(&tty_token);
2471 /* go set up the new vty screen */
2476 /* wake up processes waiting for this vty */
2477 wakeup((caddr_t)&sc->cur_scp->smode);
2479 /* wait for the controlling process to acknowledge, if necessary */
2480 if (signal_vt_acq(sc->cur_scp)) {
2482 lwkt_reltoken(&tty_token);
2486 sc->switch_in_progress = 0;
2487 if (sc->unit == sc_console_unit)
2488 cons_unavail = FALSE;
2490 DPRINTF(5, ("switch done\n"));
2492 lwkt_reltoken(&tty_token);
2497 * NOTE: must be called from a critical section because do_switch_scr
2498 * will release it temporarily.
2501 do_switch_scr(sc_softc_t *sc)
2503 lwkt_gettoken(&tty_token);
2504 vt_proc_alive(sc->new_scp);
2509 /* sc->cur_scp == sc->new_scp */
2510 wakeup((caddr_t)&sc->cur_scp->smode);
2512 /* wait for the controlling process to acknowledge, if necessary */
2513 if (!signal_vt_acq(sc->cur_scp)) {
2514 sc->switch_in_progress = 0;
2515 if (sc->unit == sc_console_unit)
2516 cons_unavail = FALSE;
2518 lwkt_reltoken(&tty_token);
2522 vt_proc_alive(scr_stat *scp)
2524 lwkt_gettoken(&tty_token);
2525 lwkt_gettoken(&proc_token);
2527 if (scp->proc == pfind(scp->pid)) {
2528 lwkt_reltoken(&proc_token);
2529 lwkt_reltoken(&tty_token);
2533 scp->smode.mode = VT_AUTO;
2534 DPRINTF(5, ("vt controlling process %d died\n", scp->pid));
2536 lwkt_reltoken(&proc_token);
2537 lwkt_reltoken(&tty_token);
2542 signal_vt_rel(scr_stat *scp)
2544 lwkt_gettoken(&tty_token);
2545 if (scp->smode.mode != VT_PROCESS) {
2546 lwkt_reltoken(&tty_token);
2549 scp->status |= SWITCH_WAIT_REL;
2550 lwkt_gettoken(&proc_token);
2551 ksignal(scp->proc, scp->smode.relsig);
2552 lwkt_reltoken(&proc_token);
2553 DPRINTF(5, ("sending relsig to %d\n", scp->pid));
2554 lwkt_reltoken(&tty_token);
2559 signal_vt_acq(scr_stat *scp)
2561 lwkt_gettoken(&tty_token);
2562 if (scp->smode.mode != VT_PROCESS) {
2563 lwkt_reltoken(&tty_token);
2566 if (scp->sc->unit == sc_console_unit)
2567 cons_unavail = TRUE;
2568 scp->status |= SWITCH_WAIT_ACQ;
2569 lwkt_gettoken(&proc_token);
2570 ksignal(scp->proc, scp->smode.acqsig);
2571 lwkt_reltoken(&proc_token);
2572 DPRINTF(5, ("sending acqsig to %d\n", scp->pid));
2573 lwkt_reltoken(&tty_token);
2578 * NOTE: must be called from a critical section because do_switch_scr
2579 * will release it temporarily.
2582 finish_vt_rel(scr_stat *scp, int release)
2584 lwkt_gettoken(&tty_token);
2585 if (scp == scp->sc->old_scp && scp->status & SWITCH_WAIT_REL) {
2586 scp->status &= ~SWITCH_WAIT_REL;
2588 do_switch_scr(scp->sc);
2590 scp->sc->switch_in_progress = 0;
2591 lwkt_reltoken(&tty_token);
2594 lwkt_reltoken(&tty_token);
2599 finish_vt_acq(scr_stat *scp)
2601 lwkt_gettoken(&tty_token);
2602 if (scp == scp->sc->new_scp && scp->status & SWITCH_WAIT_ACQ) {
2603 scp->status &= ~SWITCH_WAIT_ACQ;
2604 scp->sc->switch_in_progress = 0;
2605 lwkt_reltoken(&tty_token);
2608 lwkt_reltoken(&tty_token);
2613 exchange_scr(sc_softc_t *sc)
2617 lwkt_gettoken(&tty_token);
2618 /* save the current state of video and keyboard */
2619 sc_move_cursor(sc->old_scp, sc->old_scp->xpos, sc->old_scp->ypos);
2620 if (!ISGRAPHSC(sc->old_scp))
2621 sc_remove_cursor_image(sc->old_scp);
2622 if (sc->old_scp->kbd_mode == K_XLATE)
2623 save_kbd_state(sc->old_scp);
2625 /* set up the video for the new screen */
2626 scp = sc->cur_scp = sc->new_scp;
2627 if (sc->old_scp->mode != scp->mode || ISUNKNOWNSC(sc->old_scp))
2630 sc_vtb_init(&scp->scr, VTB_FRAMEBUFFER, scp->xsize, scp->ysize,
2631 (void *)sc->adp->va_window, FALSE);
2632 scp->status |= MOUSE_HIDDEN;
2633 sc_move_cursor(scp, scp->xpos, scp->ypos);
2634 if (!ISGRAPHSC(scp))
2635 sc_set_cursor_image(scp);
2636 #ifndef SC_NO_PALETTE_LOADING
2637 if (ISGRAPHSC(sc->old_scp))
2638 load_palette(sc->adp, sc->palette);
2640 sc_set_border(scp, scp->border);
2642 /* set up the keyboard for the new screen */
2643 if (sc->old_scp->kbd_mode != scp->kbd_mode)
2644 kbd_ioctl(sc->kbd, KDSKBMODE, (caddr_t)&scp->kbd_mode);
2645 update_kbd_state(scp, scp->status, LOCK_MASK);
2648 lwkt_reltoken(&tty_token);
2652 sc_puts(scr_stat *scp, u_char *buf, int len)
2655 /* make screensaver happy */
2656 if (!sticky_splash && scp == scp->sc->cur_scp)
2657 run_scrn_saver = FALSE;
2661 (*scp->tsw->te_puts)(scp, buf, len);
2663 if (scp->sc->delayed_next_scr)
2664 sc_switch_scr(scp->sc, scp->sc->delayed_next_scr - 1);
2669 sc_draw_cursor_image(scr_stat *scp)
2671 /* assert(scp == scp->sc->cur_scp); */
2672 ++scp->sc->videoio_in_progress;
2673 (*scp->rndr->draw_cursor)(scp, scp->cursor_pos,
2674 scp->sc->flags & SC_BLINK_CURSOR, TRUE,
2675 sc_inside_cutmark(scp, scp->cursor_pos));
2676 scp->cursor_oldpos = scp->cursor_pos;
2677 --scp->sc->videoio_in_progress;
2681 sc_remove_cursor_image(scr_stat *scp)
2683 /* assert(scp == scp->sc->cur_scp); */
2684 ++scp->sc->videoio_in_progress;
2685 (*scp->rndr->draw_cursor)(scp, scp->cursor_oldpos,
2686 scp->sc->flags & SC_BLINK_CURSOR, FALSE,
2687 sc_inside_cutmark(scp, scp->cursor_oldpos));
2688 --scp->sc->videoio_in_progress;
2692 update_cursor_image(scr_stat *scp)
2696 if (scp->sc->flags & SC_CHAR_CURSOR) {
2697 scp->cursor_base = imax(0, scp->sc->cursor_base);
2698 scp->cursor_height = imin(scp->sc->cursor_height, scp->font_size);
2700 scp->cursor_base = 0;
2701 scp->cursor_height = scp->font_size;
2703 blink = scp->sc->flags & SC_BLINK_CURSOR;
2705 /* assert(scp == scp->sc->cur_scp); */
2706 ++scp->sc->videoio_in_progress;
2707 (*scp->rndr->draw_cursor)(scp, scp->cursor_oldpos, blink, FALSE,
2708 sc_inside_cutmark(scp, scp->cursor_pos));
2709 (*scp->rndr->set_cursor)(scp, scp->cursor_base, scp->cursor_height, blink);
2710 (*scp->rndr->draw_cursor)(scp, scp->cursor_pos, blink, TRUE,
2711 sc_inside_cutmark(scp, scp->cursor_pos));
2712 --scp->sc->videoio_in_progress;
2716 sc_set_cursor_image(scr_stat *scp)
2718 if (scp->sc->flags & SC_CHAR_CURSOR) {
2719 scp->cursor_base = imax(0, scp->sc->cursor_base);
2720 scp->cursor_height = imin(scp->sc->cursor_height, scp->font_size);
2722 scp->cursor_base = 0;
2723 scp->cursor_height = scp->font_size;
2726 /* assert(scp == scp->sc->cur_scp); */
2727 ++scp->sc->videoio_in_progress;
2728 (*scp->rndr->set_cursor)(scp, scp->cursor_base, scp->cursor_height,
2729 scp->sc->flags & SC_BLINK_CURSOR);
2730 --scp->sc->videoio_in_progress;
2734 scinit(int unit, int flags)
2737 * When syscons is being initialized as the kernel console, malloc()
2738 * is not yet functional, because various kernel structures has not been
2739 * fully initialized yet. Therefore, we need to declare the following
2740 * static buffers for the console. This is less than ideal,
2741 * but is necessry evil for the time being. XXX
2743 static scr_stat main_console;
2744 static u_short sc_buffer[ROW*COL]; /* XXX */
2745 #ifndef SC_NO_FONT_LOADING
2746 static u_char font_8[256*8];
2747 static u_char font_14[256*14];
2748 static u_char font_16[256*16];
2753 video_adapter_t *adp;
2758 /* one time initialization */
2759 if (init_done == COLD)
2760 sc_get_bios_values(&bios_value);
2764 * Allocate resources. Even if we are being called for the second
2765 * time, we must allocate them again, because they might have
2768 sc = sc_get_softc(unit, flags & SC_KERNEL_CONSOLE);
2770 if (sc->adapter >= 0) {
2771 vid_release(sc->adp, (void *)&sc->adapter);
2775 if (sc->keyboard >= 0) {
2776 DPRINTF(5, ("sc%d: releasing kbd%d\n", unit, sc->keyboard));
2777 i = kbd_release(sc->kbd, (void *)&sc->keyboard);
2778 DPRINTF(5, ("sc%d: kbd_release returned %d\n", unit, i));
2779 if (sc->kbd != NULL) {
2780 DPRINTF(5, ("sc%d: kbd != NULL!, index:%d, unit:%d, flags:0x%x\n",
2781 unit, sc->kbd->kb_index, sc->kbd->kb_unit, sc->kbd->kb_flags));
2785 sc->adapter = vid_allocate("*", unit, (void *)&sc->adapter);
2786 sc->adp = vid_get_adapter(sc->adapter);
2787 /* assert((sc->adapter >= 0) && (sc->adp != NULL)) */
2788 sc->keyboard = sc_allocate_keyboard(sc, unit);
2789 DPRINTF(1, ("sc%d: keyboard %d\n", unit, sc->keyboard));
2790 sc->kbd = kbd_get_keyboard(sc->keyboard);
2791 if (sc->kbd != NULL) {
2792 DPRINTF(1, ("sc%d: kbd index:%d, unit:%d, flags:0x%x\n",
2793 unit, sc->kbd->kb_index, sc->kbd->kb_unit, sc->kbd->kb_flags));
2796 if (!(sc->flags & SC_INIT_DONE) || (adp != sc->adp)) {
2798 sc->initial_mode = sc->adp->va_initial_mode;
2800 #ifndef SC_NO_FONT_LOADING
2801 if (flags & SC_KERNEL_CONSOLE) {
2802 sc->font_8 = font_8;
2803 sc->font_14 = font_14;
2804 sc->font_16 = font_16;
2805 } else if (sc->font_8 == NULL) {
2806 /* assert(sc_malloc) */
2807 sc->font_8 = kmalloc(sizeof(font_8), M_SYSCONS, M_WAITOK);
2808 sc->font_14 = kmalloc(sizeof(font_14), M_SYSCONS, M_WAITOK);
2809 sc->font_16 = kmalloc(sizeof(font_16), M_SYSCONS, M_WAITOK);
2813 lwkt_gettoken(&tty_token);
2814 /* extract the hardware cursor location and hide the cursor for now */
2815 (*vidsw[sc->adapter]->read_hw_cursor)(sc->adp, &col, &row);
2816 (*vidsw[sc->adapter]->set_hw_cursor)(sc->adp, -1, -1);
2817 lwkt_reltoken(&tty_token);
2819 /* set up the first console */
2820 sc->first_vty = unit*MAXCONS;
2821 sc->vtys = MAXCONS; /* XXX: should be configurable */
2822 if (flags & SC_KERNEL_CONSOLE) {
2823 scp = &main_console;
2824 sc->console_scp = scp;
2825 init_scp(sc, sc->first_vty, scp);
2826 sc_vtb_init(&scp->vtb, VTB_MEMORY, scp->xsize, scp->ysize,
2827 (void *)sc_buffer, FALSE);
2828 if (sc_init_emulator(scp, SC_DFLT_TERM))
2829 sc_init_emulator(scp, "*");
2830 (*scp->tsw->te_default_attr)(scp,
2831 kernel_default.std_color,
2832 kernel_default.rev_color);
2834 /* assert(sc_malloc) */
2835 sc->dev = kmalloc(sizeof(cdev_t)*sc->vtys, M_SYSCONS, M_WAITOK | M_ZERO);
2837 sc->dev[0] = make_dev(&sc_ops, unit*MAXCONS, UID_ROOT,
2838 GID_WHEEL, 0600, "ttyv%r", unit*MAXCONS);
2840 sc->dev[0]->si_tty = ttymalloc(sc->dev[0]->si_tty);
2841 scp = alloc_scp(sc, sc->first_vty);
2842 sc->dev[0]->si_drv1 = scp;
2846 /* copy screen to temporary buffer */
2847 sc_vtb_init(&scp->scr, VTB_FRAMEBUFFER, scp->xsize, scp->ysize,
2848 (void *)scp->sc->adp->va_window, FALSE);
2850 sc_vtb_copy(&scp->scr, 0, &scp->vtb, 0, scp->xsize*scp->ysize);
2852 /* move cursors to the initial positions */
2853 if (col >= scp->xsize)
2855 if (row >= scp->ysize)
2856 row = scp->ysize - 1;
2859 scp->cursor_pos = scp->cursor_oldpos = row*scp->xsize + col;
2860 if (bios_value.cursor_end < scp->font_size)
2861 sc->cursor_base = scp->font_size - bios_value.cursor_end - 1;
2863 sc->cursor_base = 0;
2864 i = bios_value.cursor_end - bios_value.cursor_start + 1;
2865 sc->cursor_height = imin(i, scp->font_size);
2866 #ifndef SC_NO_SYSMOUSE
2867 sc_mouse_move(scp, scp->xpixel/2, scp->ypixel/2);
2869 if (!ISGRAPHSC(scp)) {
2870 sc_set_cursor_image(scp);
2871 sc_draw_cursor_image(scp);
2874 /* save font and palette */
2875 #ifndef SC_NO_FONT_LOADING
2876 sc->fonts_loaded = 0;
2877 if (ISFONTAVAIL(sc->adp->va_flags)) {
2879 bcopy(dflt_font_8, sc->font_8, sizeof(dflt_font_8));
2880 bcopy(dflt_font_14, sc->font_14, sizeof(dflt_font_14));
2881 bcopy(dflt_font_16, sc->font_16, sizeof(dflt_font_16));
2882 sc->fonts_loaded = FONT_16 | FONT_14 | FONT_8;
2883 if (scp->font_size < 14) {
2884 sc_load_font(scp, 0, 8, sc->font_8, 0, 256);
2885 } else if (scp->font_size >= 16) {
2886 sc_load_font(scp, 0, 16, sc->font_16, 0, 256);
2888 sc_load_font(scp, 0, 14, sc->font_14, 0, 256);
2890 #else /* !SC_DFLT_FONT */
2891 if (scp->font_size < 14) {
2892 sc_save_font(scp, 0, 8, sc->font_8, 0, 256);
2893 sc->fonts_loaded = FONT_8;
2894 } else if (scp->font_size >= 16) {
2895 sc_save_font(scp, 0, 16, sc->font_16, 0, 256);
2896 sc->fonts_loaded = FONT_16;
2898 sc_save_font(scp, 0, 14, sc->font_14, 0, 256);
2899 sc->fonts_loaded = FONT_14;
2901 #endif /* SC_DFLT_FONT */
2902 /* FONT KLUDGE: always use the font page #0. XXX */
2903 sc_show_font(scp, 0);
2905 #endif /* !SC_NO_FONT_LOADING */
2907 #ifndef SC_NO_PALETTE_LOADING
2908 save_palette(sc->adp, sc->palette);
2912 if (!(sc->flags & SC_SPLASH_SCRN) && (flags & SC_KERNEL_CONSOLE)) {
2913 /* we are ready to put up the splash image! */
2914 splash_init(sc->adp, scsplash_callback, sc);
2915 sc->flags |= SC_SPLASH_SCRN;
2917 #endif /* NSPLASH */
2920 /* the rest is not necessary, if we have done it once */
2921 if (sc->flags & SC_INIT_DONE) {
2925 /* initialize mapscrn arrays to a one to one map */
2926 for (i = 0; i < sizeof(sc->scr_map); i++)
2927 sc->scr_map[i] = sc->scr_rmap[i] = i;
2929 sc->flags |= SC_INIT_DONE;
2933 scterm(int unit, int flags)
2938 sc = sc_get_softc(unit, flags & SC_KERNEL_CONSOLE);
2940 return; /* shouldn't happen */
2942 lwkt_gettoken(&tty_token);
2944 /* this console is no longer available for the splash screen */
2945 if (sc->flags & SC_SPLASH_SCRN) {
2946 splash_term(sc->adp);
2947 sc->flags &= ~SC_SPLASH_SCRN;
2949 #endif /* NSPLASH */
2952 /* move the hardware cursor to the upper-left corner */
2953 (*vidsw[sc->adapter]->set_hw_cursor)(sc->adp, 0, 0);
2956 /* release the keyboard and the video card */
2957 if (sc->keyboard >= 0)
2958 kbd_release(sc->kbd, &sc->keyboard);
2959 if (sc->adapter >= 0)
2960 vid_release(sc->adp, &sc->adapter);
2963 * Stop the terminal emulator, if any. If operating on the
2964 * kernel console sc->dev may not be setup yet.
2966 if (flags & SC_KERNEL_CONSOLE)
2967 scp = sc->console_scp;
2969 scp = SC_STAT(sc->dev[0]);
2971 (*scp->tsw->te_term)(scp, &scp->ts);
2972 if (scp->ts != NULL)
2973 kfree(scp->ts, M_SYSCONS);
2975 /* clear the structure */
2976 if (!(flags & SC_KERNEL_CONSOLE)) {
2977 /* XXX: We need delete_dev() for this */
2978 kfree(sc->dev, M_SYSCONS);
2980 /* XXX: We need a ttyunregister for this */
2981 kfree(sc->tty, M_SYSCONS);
2983 #ifndef SC_NO_FONT_LOADING
2984 kfree(sc->font_8, M_SYSCONS);
2985 kfree(sc->font_14, M_SYSCONS);
2986 kfree(sc->font_16, M_SYSCONS);
2988 /* XXX vtb, history */
2990 bzero(sc, sizeof(*sc));
2993 lwkt_reltoken(&tty_token);
2997 scshutdown(void *arg, int howto)
2999 /* assert(sc_console != NULL) */
3001 lwkt_gettoken(&tty_token);
3002 sc_touch_scrn_saver();
3003 if (!cold && sc_console
3004 && sc_console->sc->cur_scp->smode.mode == VT_AUTO
3005 && sc_console->smode.mode == VT_AUTO)
3006 sc_switch_scr(sc_console->sc, sc_console->index);
3007 shutdown_in_progress = TRUE;
3008 lwkt_reltoken(&tty_token);
3012 sc_clean_up(scr_stat *scp)
3016 #endif /* NSPLASH */
3018 lwkt_gettoken(&tty_token);
3019 if (scp->sc->flags & SC_SCRN_BLANKED) {
3020 sc_touch_scrn_saver();
3022 if ((error = wait_scrn_saver_stop(scp->sc))) {
3023 lwkt_reltoken(&tty_token);
3026 #endif /* NSPLASH */
3028 scp->status |= MOUSE_HIDDEN;
3029 sc_remove_mouse_image(scp);
3030 sc_remove_cutmarking(scp);
3031 lwkt_reltoken(&tty_token);
3036 sc_alloc_scr_buffer(scr_stat *scp, int wait, int discard)
3041 lwkt_gettoken(&tty_token);
3043 sc_vtb_init(&new, VTB_MEMORY, scp->xsize, scp->ysize, NULL, wait);
3044 if (!discard && (old.vtb_flags & VTB_VALID)) {
3045 /* retain the current cursor position and buffer contants */
3046 scp->cursor_oldpos = scp->cursor_pos;
3048 * This works only if the old buffer has the same size as or larger
3049 * than the new one. XXX
3051 sc_vtb_copy(&old, 0, &new, 0, scp->xsize*scp->ysize);
3055 sc_vtb_destroy(&old);
3058 #ifndef SC_NO_SYSMOUSE
3059 /* move the mouse cursor at the center of the screen */
3060 sc_mouse_move(scp, scp->xpixel / 2, scp->ypixel / 2);
3062 lwkt_reltoken(&tty_token);
3066 alloc_scp(sc_softc_t *sc, int vty)
3070 /* assert(sc_malloc) */
3072 scp = kmalloc(sizeof(scr_stat), M_SYSCONS, M_WAITOK);
3073 init_scp(sc, vty, scp);
3075 sc_alloc_scr_buffer(scp, TRUE, TRUE);
3076 if (sc_init_emulator(scp, SC_DFLT_TERM))
3077 sc_init_emulator(scp, "*");
3079 #ifndef SC_NO_CUTPASTE
3080 sc_alloc_cut_buffer(scp, TRUE);
3083 #ifndef SC_NO_HISTORY
3084 sc_alloc_history_buffer(scp, 0, 0, TRUE);
3090 * NOTE: Must be called with tty_token held.
3093 init_scp(sc_softc_t *sc, int vty, scr_stat *scp)
3097 bzero(scp, sizeof(*scp));
3102 scp->mode = sc->initial_mode;
3103 callout_init(&scp->blink_screen_ch);
3104 lwkt_gettoken(&tty_token);
3105 (*vidsw[sc->adapter]->get_info)(sc->adp, scp->mode, &info);
3106 lwkt_reltoken(&tty_token);
3107 if (info.vi_flags & V_INFO_GRAPHICS) {
3108 scp->status |= GRAPHICS_MODE;
3109 scp->xpixel = info.vi_width;
3110 scp->ypixel = info.vi_height;
3111 scp->xsize = info.vi_width/8;
3112 scp->ysize = info.vi_height/info.vi_cheight;
3116 scp->xsize = info.vi_width;
3117 scp->ysize = info.vi_height;
3118 scp->xpixel = scp->xsize*8;
3119 scp->ypixel = scp->ysize*info.vi_cheight;
3120 if (info.vi_cheight < 14) {
3122 #ifndef SC_NO_FONT_LOADING
3123 scp->font = sc->font_8;
3127 } else if (info.vi_cheight >= 16) {
3128 scp->font_size = 16;
3129 #ifndef SC_NO_FONT_LOADING
3130 scp->font = sc->font_16;
3135 scp->font_size = 14;
3136 #ifndef SC_NO_FONT_LOADING
3137 scp->font = sc->font_14;
3143 sc_vtb_init(&scp->vtb, VTB_MEMORY, 0, 0, NULL, FALSE);
3144 sc_vtb_init(&scp->scr, VTB_FRAMEBUFFER, 0, 0, NULL, FALSE);
3145 scp->xoff = scp->yoff = 0;
3146 scp->xpos = scp->ypos = 0;
3147 scp->start = scp->xsize * scp->ysize - 1;
3152 scp->border = BG_BLACK;
3153 scp->cursor_base = sc->cursor_base;
3154 scp->cursor_height = imin(sc->cursor_height, scp->font_size);
3155 scp->mouse_cut_start = scp->xsize*scp->ysize;
3156 scp->mouse_cut_end = -1;
3157 scp->mouse_signal = 0;
3159 scp->mouse_proc = NULL;
3160 scp->kbd_mode = K_XLATE;
3161 scp->bell_pitch = bios_value.bell_pitch;
3162 scp->bell_duration = BELL_DURATION;
3163 scp->status |= (bios_value.shift_state & NLKED);
3164 scp->status |= CURSOR_ENABLED | MOUSE_HIDDEN;
3167 scp->smode.mode = VT_AUTO;
3168 scp->history = NULL;
3169 scp->history_pos = 0;
3170 scp->history_size = 0;
3174 sc_init_emulator(scr_stat *scp, char *name)
3181 if (name == NULL) /* if no name is given, use the current emulator */
3183 else /* ...otherwise find the named emulator */
3184 sw = sc_term_match(name);
3190 if (strcmp(sw->te_renderer, "*") != 0) {
3191 rndr = sc_render_match(scp, sw->te_renderer, scp->model);
3194 rndr = sc_render_match(scp, scp->sc->adp->va_name, scp->model);
3200 if (sw == scp->tsw) {
3201 error = (*sw->te_init)(scp, &scp->ts, SC_TE_WARM_INIT);
3203 sc_clear_screen(scp);
3204 /* assert(error == 0); */
3208 if (sc_malloc && (sw->te_size > 0))
3209 p = kmalloc(sw->te_size, M_SYSCONS, M_NOWAIT);
3212 error = (*sw->te_init)(scp, &p, SC_TE_COLD_INIT);
3218 (*scp->tsw->te_term)(scp, &scp->ts);
3219 if (scp->ts != NULL)
3220 kfree(scp->ts, M_SYSCONS);
3226 (*sw->te_default_attr)(scp, user_default.std_color, user_default.rev_color);
3227 sc_clear_screen(scp);
3233 * scgetc(flags) - get character from keyboard.
3234 * If flags & SCGETC_CN, then avoid harmful side effects.
3235 * If flags & SCGETC_NONBLOCK, then wait until a key is pressed, else
3236 * return NOKEY if there is nothing there.
3239 scgetc(sc_softc_t *sc, u_int flags)
3242 #ifndef SC_NO_HISTORY
3250 lwkt_gettoken(&tty_token);
3251 if (sc->kbd == NULL) {
3252 lwkt_reltoken(&tty_token);
3258 /* I don't like this, but... XXX */
3259 if (flags & SCGETC_CN) {
3261 sccnupdate(sc->cur_scp);
3266 /* first see if there is something in the keyboard port */
3268 c = kbd_read_char(sc->kbd, !(flags & SCGETC_NONBLOCK));
3270 if (!(flags & SCGETC_CN))
3271 sc_bell(scp, bios_value.bell_pitch, BELL_DURATION);
3272 } else if (c == NOKEY) {
3273 lwkt_reltoken(&tty_token);
3280 /* make screensaver happy */
3282 sc_touch_scrn_saver();
3284 if (!(flags & SCGETC_CN))
3285 /* do the /dev/random device a favour */
3286 add_keyboard_randomness(c);
3288 if (scp->kbd_mode != K_XLATE) {
3289 lwkt_reltoken(&tty_token);
3293 /* if scroll-lock pressed allow history browsing */
3294 if (!ISGRAPHSC(scp) && scp->history && scp->status & SLKED) {
3296 scp->status &= ~CURSOR_ENABLED;
3297 sc_remove_cursor_image(scp);
3299 #ifndef SC_NO_HISTORY
3300 if (!(scp->status & BUFFER_SAVED)) {
3301 scp->status |= BUFFER_SAVED;
3305 /* FIXME: key codes */
3306 case SPCLKEY | FKEY | F(49): /* home key */
3307 sc_remove_cutmarking(scp);
3311 case SPCLKEY | FKEY | F(57): /* end key */
3312 sc_remove_cutmarking(scp);
3316 case SPCLKEY | FKEY | F(50): /* up arrow key */
3317 sc_remove_cutmarking(scp);
3318 if (sc_hist_up_line(scp))
3319 if (!(flags & SCGETC_CN))
3320 sc_bell(scp, bios_value.bell_pitch, BELL_DURATION);
3323 case SPCLKEY | FKEY | F(58): /* down arrow key */
3324 sc_remove_cutmarking(scp);
3325 if (sc_hist_down_line(scp))
3326 if (!(flags & SCGETC_CN))
3327 sc_bell(scp, bios_value.bell_pitch, BELL_DURATION);
3330 case SPCLKEY | FKEY | F(51): /* page up key */
3331 sc_remove_cutmarking(scp);
3332 for (i=0; i<scp->ysize; i++)
3333 if (sc_hist_up_line(scp)) {
3334 if (!(flags & SCGETC_CN))
3335 sc_bell(scp, bios_value.bell_pitch, BELL_DURATION);
3340 case SPCLKEY | FKEY | F(59): /* page down key */
3341 sc_remove_cutmarking(scp);
3342 for (i=0; i<scp->ysize; i++)
3343 if (sc_hist_down_line(scp)) {
3344 if (!(flags & SCGETC_CN))
3345 sc_bell(scp, bios_value.bell_pitch, BELL_DURATION);
3350 #endif /* SC_NO_HISTORY */
3354 * Process and consume special keys here. Return a plain char code
3355 * or a char code with the META flag or a function key code.
3359 /* goto next_code */
3364 switch (KEYCHAR(c)) {
3366 case NLK: case CLK: case ALK:
3369 kbd_ioctl(sc->kbd, KDGKBSTATE, (caddr_t)&f);
3371 scp->status |= SLKED;
3373 if (scp->status & SLKED) {
3374 scp->status &= ~SLKED;
3375 #ifndef SC_NO_HISTORY
3376 if (scp->status & BUFFER_SAVED) {
3377 if (!sc_hist_restore(scp))
3378 sc_remove_cutmarking(scp);
3379 scp->status &= ~BUFFER_SAVED;
3380 scp->status |= CURSOR_ENABLED;
3381 sc_draw_cursor_image(scp);
3383 tp = VIRTUAL_TTY(sc, scp->index);
3391 /* NON-LOCKING KEYS */
3393 case LSH: case RSH: case LCTR: case RCTR:
3394 case LALT: case RALT: case ASH: case META:
3398 if (!(sc->flags & SC_SCRN_BLANKED)) {
3399 lwkt_reltoken(&tty_token);
3406 /* force activatation/deactivation of the screen saver */
3407 if (!(sc->flags & SC_SCRN_BLANKED)) {
3408 run_scrn_saver = TRUE;
3409 sc->scrn_time_stamp -= scrn_blank_time;
3413 * While devices are being probed, the screen saver need
3414 * to be invoked explictly. XXX
3416 if (sc->flags & SC_SCRN_BLANKED) {
3417 scsplash_stick(FALSE);
3418 stop_scrn_saver(sc, current_saver);
3420 if (!ISGRAPHSC(scp)) {
3421 scsplash_stick(TRUE);
3422 (*current_saver)(sc, TRUE);
3426 #endif /* NSPLASH */
3430 #ifndef SC_DISABLE_REBOOT
3436 #ifndef SC_DISABLE_REBOOT
3437 shutdown_nice(RB_HALT);
3442 #ifndef SC_DISABLE_REBOOT
3443 shutdown_nice(RB_HALT|RB_POWEROFF);
3449 apm_suspend(PMST_SUSPEND);
3452 apm_suspend(PMST_STANDBY);
3461 #ifndef SC_DISABLE_DDBKEY
3463 lwkt_reltoken(&tty_token);
3464 Debugger("manual escape to debugger");
3465 lwkt_gettoken(&tty_token);
3467 kprintf("No debugger in kernel\n");
3469 #else /* SC_DISABLE_DDBKEY */
3471 #endif /* SC_DISABLE_DDBKEY */
3475 if (enable_panic_key)
3476 panic("Forced by the panic key");
3480 this_scr = scp->index;
3481 for (i = (this_scr - sc->first_vty + 1)%sc->vtys;
3482 sc->first_vty + i != this_scr;
3483 i = (i + 1)%sc->vtys) {
3484 struct tty *tp = VIRTUAL_TTY(sc, sc->first_vty + i);
3485 if (ISTTYOPEN(tp)) {
3486 sc_switch_scr(scp->sc, sc->first_vty + i);
3493 this_scr = scp->index;
3494 for (i = (this_scr - sc->first_vty + sc->vtys - 1)%sc->vtys;
3495 sc->first_vty + i != this_scr;
3496 i = (i + sc->vtys - 1)%sc->vtys) {
3497 struct tty *tp = VIRTUAL_TTY(sc, sc->first_vty + i);
3498 if (ISTTYOPEN(tp)) {
3499 sc_switch_scr(scp->sc, sc->first_vty + i);
3506 if (KEYCHAR(c) >= F_SCR && KEYCHAR(c) <= L_SCR) {
3507 sc_switch_scr(scp->sc, sc->first_vty + KEYCHAR(c) - F_SCR);
3510 /* assert(c & FKEY) */
3511 if (!(sc->flags & SC_SCRN_BLANKED)) {
3512 lwkt_reltoken(&tty_token);
3517 /* goto next_code */
3519 /* regular keys (maybe MKEY is set) */
3520 if (!(sc->flags & SC_SCRN_BLANKED)) {
3521 lwkt_reltoken(&tty_token);
3531 scmmap(struct dev_mmap_args *ap)
3535 lwkt_gettoken(&tty_token);
3536 scp = SC_STAT(ap->a_head.a_dev);
3537 if (scp != scp->sc->cur_scp) {
3538 lwkt_reltoken(&tty_token);
3541 ap->a_result = (*vidsw[scp->sc->adapter]->mmap)(scp->sc->adp, ap->a_offset,
3543 lwkt_reltoken(&tty_token);
3548 save_kbd_state(scr_stat *scp)
3553 error = kbd_ioctl(scp->sc->kbd, KDGKBSTATE, (caddr_t)&state);
3554 if (error == ENOIOCTL)
3557 scp->status &= ~LOCK_MASK;
3558 scp->status |= state;
3564 update_kbd_state(scr_stat *scp, int new_bits, int mask)
3569 if (mask != LOCK_MASK) {
3570 error = kbd_ioctl(scp->sc->kbd, KDGKBSTATE, (caddr_t)&state);
3571 if (error == ENOIOCTL)
3577 state |= new_bits & mask;
3579 state = new_bits & LOCK_MASK;
3581 error = kbd_ioctl(scp->sc->kbd, KDSKBSTATE, (caddr_t)&state);
3582 if (error == ENOIOCTL)
3588 update_kbd_leds(scr_stat *scp, int which)
3593 error = kbd_ioctl(scp->sc->kbd, KDSETLED, (caddr_t)&which);
3594 if (error == ENOIOCTL)
3600 set_mode(scr_stat *scp)
3604 lwkt_gettoken(&tty_token);
3605 /* reject unsupported mode */
3606 if ((*vidsw[scp->sc->adapter]->get_info)(scp->sc->adp, scp->mode, &info)) {
3607 lwkt_reltoken(&tty_token);
3611 /* if this vty is not currently showing, do nothing */
3612 if (scp != scp->sc->cur_scp) {
3613 lwkt_reltoken(&tty_token);
3617 /* setup video hardware for the given mode */
3618 (*vidsw[scp->sc->adapter]->set_mode)(scp->sc->adp, scp->mode);
3619 sc_vtb_init(&scp->scr, VTB_FRAMEBUFFER, scp->xsize, scp->ysize,
3620 (void *)scp->sc->adp->va_window, FALSE);
3622 #ifndef SC_NO_FONT_LOADING
3623 /* load appropriate font */
3624 if (!(scp->status & GRAPHICS_MODE)) {
3625 if (!(scp->status & PIXEL_MODE) && ISFONTAVAIL(scp->sc->adp->va_flags)) {
3626 if (scp->font_size < 14) {
3627 if (scp->sc->fonts_loaded & FONT_8)
3628 sc_load_font(scp, 0, 8, scp->sc->font_8, 0, 256);
3629 } else if (scp->font_size >= 16) {
3630 if (scp->sc->fonts_loaded & FONT_16)
3631 sc_load_font(scp, 0, 16, scp->sc->font_16, 0, 256);
3633 if (scp->sc->fonts_loaded & FONT_14)
3634 sc_load_font(scp, 0, 14, scp->sc->font_14, 0, 256);
3638 * This is an interim kludge to display correct font.
3639 * Always use the font page #0 on the video plane 2.
3640 * Somehow we cannot show the font in other font pages on
3641 * some video cards... XXX
3643 sc_show_font(scp, 0);
3647 #endif /* !SC_NO_FONT_LOADING */
3649 sc_set_border(scp, scp->border);
3650 sc_set_cursor_image(scp);
3652 lwkt_reltoken(&tty_token);
3657 refresh_ega_palette(scr_stat *scp)
3661 int rsize, gsize, bsize;
3662 int rfld, gfld, bfld;
3665 rsize = scp->sc->adp->va_info.vi_pixel_fsizes[0];
3666 gsize = scp->sc->adp->va_info.vi_pixel_fsizes[1];
3667 bsize = scp->sc->adp->va_info.vi_pixel_fsizes[2];
3668 rfld = scp->sc->adp->va_info.vi_pixel_fields[0];
3669 gfld = scp->sc->adp->va_info.vi_pixel_fields[1];
3670 bfld = scp->sc->adp->va_info.vi_pixel_fields[2];
3672 for (i = 0; i < 16; i++) {
3673 reg = scp->sc->adp->va_palette_regs[i];
3675 r = scp->sc->palette[reg * 3] >> (8 - rsize);
3676 g = scp->sc->palette[reg * 3 + 1] >> (8 - gsize);
3677 b = scp->sc->palette[reg * 3 + 2] >> (8 - bsize);
3679 scp->ega_palette[i] = (r << rfld) + (g << gfld) + (b << bfld);
3684 sc_set_border(scr_stat *scp, int color)
3686 ++scp->sc->videoio_in_progress;
3687 (*scp->rndr->draw_border)(scp, color);
3688 --scp->sc->videoio_in_progress;
3691 #ifndef SC_NO_FONT_LOADING
3693 sc_load_font(scr_stat *scp, int page, int size, u_char *buf,
3694 int base, int count)
3699 sc->font_loading_in_progress = TRUE;
3700 (*vidsw[sc->adapter]->load_font)(sc->adp, page, size, buf, base, count);
3701 sc->font_loading_in_progress = FALSE;
3705 sc_save_font(scr_stat *scp, int page, int size, u_char *buf,
3706 int base, int count)
3711 sc->font_loading_in_progress = TRUE;
3712 (*vidsw[sc->adapter]->save_font)(sc->adp, page, size, buf, base, count);
3713 sc->font_loading_in_progress = FALSE;
3717 sc_show_font(scr_stat *scp, int page)
3719 (*vidsw[scp->sc->adapter]->show_font)(scp->sc->adp, page);
3721 #endif /* !SC_NO_FONT_LOADING */
3724 sc_paste(scr_stat *scp, u_char *p, int count)
3729 lwkt_gettoken(&tty_token);
3730 if (scp->status & MOUSE_VISIBLE) {
3731 tp = VIRTUAL_TTY(scp->sc, scp->sc->cur_scp->index);
3732 if (!ISTTYOPEN(tp)) {
3733 lwkt_reltoken(&tty_token);
3736 rmap = scp->sc->scr_rmap;
3737 for (; count > 0; --count)
3738 (*linesw[tp->t_line].l_rint)(rmap[*p++], tp);
3740 lwkt_reltoken(&tty_token);
3744 sc_bell(scr_stat *scp, int pitch, int duration)
3746 if (cold || shutdown_in_progress)
3749 if (scp != scp->sc->cur_scp && (scp->sc->flags & SC_QUIET_BELL)) {
3753 if (scp->sc->flags & SC_VISUAL_BELL) {
3754 if (scp->sc->blink_in_progress) {
3757 scp->sc->blink_in_progress = 3;
3758 if (scp != scp->sc->cur_scp)
3759 scp->sc->blink_in_progress += 2;
3760 blink_screen(scp->sc->cur_scp);
3761 } else if (duration != 0 && pitch != 0) {
3762 if (scp != scp->sc->cur_scp)
3764 sysbeep(pitch, duration);
3769 blink_screen(void *arg)
3771 scr_stat *scp = arg;
3774 if (ISGRAPHSC(scp) || (scp->sc->blink_in_progress <= 1)) {
3775 scp->sc->blink_in_progress = 0;
3777 tp = VIRTUAL_TTY(scp->sc, scp->index);
3780 if (scp->sc->delayed_next_scr)
3781 sc_switch_scr(scp->sc, scp->sc->delayed_next_scr - 1);
3784 (*scp->rndr->draw)(scp, 0, scp->xsize*scp->ysize,
3785 scp->sc->blink_in_progress & 1);
3786 scp->sc->blink_in_progress--;
3787 callout_reset(&scp->blink_screen_ch, hz / 10, blink_screen, scp);
3793 * Allocate active keyboard. Try to allocate "kbdmux" keyboard first, and,
3794 * if found, add all non-busy keyboards to "kbdmux". Otherwise look for
3799 sc_allocate_keyboard(sc_softc_t *sc, int unit)
3805 idx0 = kbd_allocate("kbdmux", -1, (void *)&sc->keyboard, sckbdevent, sc);
3807 k0 = kbd_get_keyboard(idx0);
3809 for (idx = kbd_find_keyboard2("*", -1, 0, 0);
3811 idx = kbd_find_keyboard2("*", -1, idx + 1, 0)) {
3812 k = kbd_get_keyboard(idx);
3814 if (idx == idx0 || KBD_IS_BUSY(k))
3817 bzero(&ki, sizeof(ki));
3818 strcpy(ki.kb_name, k->kb_name);
3819 ki.kb_unit = k->kb_unit;
3821 kbd_ioctl(k0, KBADDKBD, (caddr_t) &ki);
3824 idx0 = kbd_allocate("*", unit, (void *)&sc->keyboard, sckbdevent, sc);