2 * Copyright (c) 2009, 2013 The FreeBSD Foundation
5 * This software was developed by Ed Schouten under sponsorship from the
8 * Portions of this software were developed by Oleksandr Rybalko
9 * under sponsorship from the FreeBSD Foundation.
11 * Redistribution and use in source and binary forms, with or without
12 * modification, are permitted provided that the following conditions
14 * 1. Redistributions of source code must retain the above copyright
15 * notice, this list of conditions and the following disclaimer.
16 * 2. Redistributions in binary form must reproduce the above copyright
17 * notice, this list of conditions and the following disclaimer in the
18 * documentation and/or other materials provided with the distribution.
20 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
21 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
23 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
24 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
25 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
26 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
27 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
28 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
29 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
33 #include <sys/cdefs.h>
34 __FBSDID("$FreeBSD$");
36 #include "opt_compat.h"
38 #include <sys/param.h>
39 #include <sys/consio.h>
40 #include <sys/eventhandler.h>
44 #include <sys/kernel.h>
46 #include <sys/malloc.h>
47 #include <sys/mutex.h>
48 #include <sys/power.h>
51 #include <sys/reboot.h>
52 #include <sys/systm.h>
53 #include <sys/terminal.h>
55 #include <dev/kbd/kbdreg.h>
56 #include <dev/vt/vt.h>
58 #if defined(__i386__) || defined(__amd64__)
59 #include <machine/psl.h>
60 #include <machine/frame.h>
63 static tc_bell_t vtterm_bell;
64 static tc_cursor_t vtterm_cursor;
65 static tc_putchar_t vtterm_putchar;
66 static tc_fill_t vtterm_fill;
67 static tc_copy_t vtterm_copy;
68 static tc_param_t vtterm_param;
69 static tc_done_t vtterm_done;
71 static tc_cnprobe_t vtterm_cnprobe;
72 static tc_cngetc_t vtterm_cngetc;
74 static tc_cngrab_t vtterm_cngrab;
75 static tc_cnungrab_t vtterm_cnungrab;
77 static tc_opened_t vtterm_opened;
78 static tc_ioctl_t vtterm_ioctl;
79 static tc_mmap_t vtterm_mmap;
81 const struct terminal_class vt_termclass = {
82 .tc_bell = vtterm_bell,
83 .tc_cursor = vtterm_cursor,
84 .tc_putchar = vtterm_putchar,
85 .tc_fill = vtterm_fill,
86 .tc_copy = vtterm_copy,
87 .tc_param = vtterm_param,
88 .tc_done = vtterm_done,
90 .tc_cnprobe = vtterm_cnprobe,
91 .tc_cngetc = vtterm_cngetc,
93 .tc_cngrab = vtterm_cngrab,
94 .tc_cnungrab = vtterm_cnungrab,
96 .tc_opened = vtterm_opened,
97 .tc_ioctl = vtterm_ioctl,
98 .tc_mmap = vtterm_mmap,
102 * Use a constant timer of 25 Hz to redraw the screen.
104 * XXX: In theory we should only fire up the timer when there is really
105 * activity. Unfortunately we cannot always start timers. We really
106 * don't want to process kernel messages synchronously, because it
107 * really slows down the system.
109 #define VT_TIMERFREQ 25
111 /* Bell pitch/duration. */
112 #define VT_BELLDURATION ((5 * hz + 99) / 100)
113 #define VT_BELLPITCH 800
115 #define VT_LOCK(vd) mtx_lock(&(vd)->vd_lock)
116 #define VT_UNLOCK(vd) mtx_unlock(&(vd)->vd_lock)
117 #define VT_LOCK_ASSERT(vd, what) mtx_assert(&(vd)->vd_lock, what)
119 #define VT_UNIT(vw) ((vw)->vw_device->vd_unit * VT_MAXWINDOWS + \
122 static SYSCTL_NODE(_kern, OID_AUTO, vt, CTLFLAG_RD, 0, "vt(9) parameters");
123 VT_SYSCTL_INT(enable_altgr, 1, "Enable AltGr key (Do not assume R.Alt as Alt)");
124 VT_SYSCTL_INT(debug, 0, "vt(9) debug level");
125 VT_SYSCTL_INT(deadtimer, 15, "Time to wait busy process in VT_PROCESS mode");
126 VT_SYSCTL_INT(suspendswitch, 1, "Switch to VT0 before suspend");
128 /* Allow to disable some keyboard combinations. */
129 VT_SYSCTL_INT(kbd_halt, 1, "Enable halt keyboard combination. "
130 "See kbdmap(5) to configure.");
131 VT_SYSCTL_INT(kbd_poweroff, 1, "Enable Power Off keyboard combination. "
132 "See kbdmap(5) to configure.");
133 VT_SYSCTL_INT(kbd_reboot, 1, "Enable reboot keyboard combination. "
134 "See kbdmap(5) to configure (typically Ctrl-Alt-Delete).");
135 VT_SYSCTL_INT(kbd_debug, 1, "Enable key combination to enter debugger. "
136 "See kbdmap(5) to configure (typically Ctrl-Alt-Esc).");
137 VT_SYSCTL_INT(kbd_panic, 0, "Enable request to panic. "
138 "See kbdmap(5) to configure.");
140 static struct vt_device vt_consdev;
141 static unsigned int vt_unit = 0;
142 static MALLOC_DEFINE(M_VT, "vt", "vt device");
143 struct vt_device *main_vd = &vt_consdev;
146 extern unsigned int vt_logo_width;
147 extern unsigned int vt_logo_height;
148 extern unsigned int vt_logo_depth;
149 extern unsigned char vt_logo_image[];
152 extern struct vt_font vt_font_default;
153 #ifndef SC_NO_CUTPASTE
154 extern struct vt_mouse_cursor vt_default_mouse_pointer;
157 static int signal_vt_rel(struct vt_window *);
158 static int signal_vt_acq(struct vt_window *);
159 static int finish_vt_rel(struct vt_window *, int, int *);
160 static int finish_vt_acq(struct vt_window *);
161 static int vt_window_switch(struct vt_window *);
162 static int vt_late_window_switch(struct vt_window *);
163 static int vt_proc_alive(struct vt_window *);
164 static void vt_resize(struct vt_device *);
165 static void vt_update_static(void *);
166 #ifndef SC_NO_CUTPASTE
167 static void vt_mouse_paste(void);
169 static void vt_suspend_handler(void *priv);
170 static void vt_resume_handler(void *priv);
172 SET_DECLARE(vt_drv_set, struct vt_driver);
174 #define _VTDEFH MAX(100, PIXEL_HEIGHT(VT_FB_DEFAULT_HEIGHT))
175 #define _VTDEFW MAX(200, PIXEL_WIDTH(VT_FB_DEFAULT_WIDTH))
177 static struct terminal vt_consterm;
178 static struct vt_window vt_conswindow;
179 static struct vt_device vt_consdev = {
182 .vd_flags = VDF_INVALID,
183 .vd_windows = { [VT_CONSWINDOW] = &vt_conswindow, },
184 .vd_curwindow = &vt_conswindow,
187 #ifndef SC_NO_CUTPASTE
193 .vd_mcursor = &vt_default_mouse_pointer,
194 .vd_mcursor_fg = TC_WHITE,
195 .vd_mcursor_bg = TC_BLACK,
198 static term_char_t vt_constextbuf[(_VTDEFW) * (VBF_DEFAULT_HISTORY_SIZE)];
199 static term_char_t *vt_constextbufrows[VBF_DEFAULT_HISTORY_SIZE];
200 static struct vt_window vt_conswindow = {
201 .vw_number = VT_CONSWINDOW,
202 .vw_flags = VWF_CONSOLE,
204 .vb_buffer = &vt_constextbuf[0],
205 .vb_rows = &vt_constextbufrows[0],
206 .vb_history_size = VBF_DEFAULT_HISTORY_SIZE,
209 .vb_flags = VBF_STATIC,
210 .vb_mark_start = {.tp_row = 0, .tp_col = 0,},
211 .vb_mark_end = {.tp_row = 0, .tp_col = 0,},
217 .vw_device = &vt_consdev,
218 .vw_terminal = &vt_consterm,
219 .vw_kbdmode = K_XLATE,
222 static struct terminal vt_consterm = {
223 .tm_class = &vt_termclass,
224 .tm_softc = &vt_conswindow,
227 static struct consdev vt_consterm_consdev = {
228 .cn_ops = &termcn_cnops,
229 .cn_arg = &vt_consterm,
233 /* Add to set of consoles. */
234 DATA_SET(cons_set, vt_consterm_consdev);
237 * Right after kmem is done to allow early drivers to use locking and allocate
240 SYSINIT(vt_update_static, SI_SUB_KMEM, SI_ORDER_ANY, vt_update_static,
242 /* Delay until all devices attached, to not waste time. */
243 SYSINIT(vt_early_cons, SI_SUB_INT_CONFIG_HOOKS, SI_ORDER_ANY, vt_upgrade,
246 /* Initialize locks/mem depended members. */
248 vt_update_static(void *dummy)
251 if (!vty_enabled(VTY_VT))
253 if (main_vd->vd_driver != NULL)
254 printf("VT: running with driver \"%s\".\n",
255 main_vd->vd_driver->vd_name);
257 printf("VT: init without driver.\n");
259 mtx_init(&main_vd->vd_lock, "vtdev", NULL, MTX_DEF);
260 cv_init(&main_vd->vd_winswitch, "vtwswt");
264 vt_schedule_flush(struct vt_device *vd, int ms)
268 /* Default to initial value. */
269 ms = 1000 / VT_TIMERFREQ;
271 callout_schedule(&vd->vd_timer, hz / (1000 / ms));
275 vt_resume_flush_timer(struct vt_device *vd, int ms)
278 if (!(vd->vd_flags & VDF_ASYNC) ||
279 !atomic_cmpset_int(&vd->vd_timer_armed, 0, 1))
282 vt_schedule_flush(vd, ms);
286 vt_suspend_flush_timer(struct vt_device *vd)
289 * As long as this function is called locked, callout_stop()
290 * has the same effect like callout_drain() with regard to
291 * preventing the callback function from executing.
293 VT_LOCK_ASSERT(vd, MA_OWNED);
295 if (!(vd->vd_flags & VDF_ASYNC) ||
296 !atomic_cmpset_int(&vd->vd_timer_armed, 1, 0))
299 callout_stop(&vd->vd_timer);
303 vt_switch_timer(void *arg)
306 vt_late_window_switch((struct vt_window *)arg);
310 vt_save_kbd_mode(struct vt_window *vw, keyboard_t *kbd)
315 ret = kbdd_ioctl(kbd, KDGKBMODE, (caddr_t)&mode);
321 vw->vw_kbdmode = mode;
327 vt_update_kbd_mode(struct vt_window *vw, keyboard_t *kbd)
331 ret = kbdd_ioctl(kbd, KDSKBMODE, (caddr_t)&vw->vw_kbdmode);
339 vt_save_kbd_state(struct vt_window *vw, keyboard_t *kbd)
344 ret = kbdd_ioctl(kbd, KDGKBSTATE, (caddr_t)&state);
350 vw->vw_kbdstate &= ~LOCK_MASK;
351 vw->vw_kbdstate |= state & LOCK_MASK;
357 vt_update_kbd_state(struct vt_window *vw, keyboard_t *kbd)
361 state = vw->vw_kbdstate & LOCK_MASK;
362 ret = kbdd_ioctl(kbd, KDSKBSTATE, (caddr_t)&state);
370 vt_save_kbd_leds(struct vt_window *vw, keyboard_t *kbd)
375 ret = kbdd_ioctl(kbd, KDGETLED, (caddr_t)&leds);
381 vw->vw_kbdstate &= ~LED_MASK;
382 vw->vw_kbdstate |= leds & LED_MASK;
388 vt_update_kbd_leds(struct vt_window *vw, keyboard_t *kbd)
392 leds = vw->vw_kbdstate & LED_MASK;
393 ret = kbdd_ioctl(kbd, KDSETLED, (caddr_t)&leds);
401 vt_window_preswitch(struct vt_window *vw, struct vt_window *curvw)
404 DPRINTF(40, "%s\n", __func__);
405 curvw->vw_switch_to = vw;
406 /* Set timer to allow switch in case when process hang. */
407 callout_reset(&vw->vw_proc_dead_timer, hz * vt_deadtimer,
408 vt_switch_timer, (void *)vw);
409 /* Notify process about vt switch attempt. */
410 DPRINTF(30, "%s: Notify process.\n", __func__);
411 signal_vt_rel(curvw);
417 vt_window_postswitch(struct vt_window *vw)
424 /* vt_late_window_switch will done VT switching for regular case. */
426 vt_late_window_switch(struct vt_window *vw)
430 callout_stop(&vw->vw_proc_dead_timer);
432 ret = vt_window_switch(vw);
436 /* Notify owner process about terminal availability. */
437 if (vw->vw_smode.mode == VT_PROCESS) {
438 ret = vt_window_postswitch(vw);
445 vt_proc_window_switch(struct vt_window *vw)
447 struct vt_window *curvw;
448 struct vt_device *vd;
451 /* Prevent switching to NULL */
453 DPRINTF(30, "%s: Cannot switch: vw is NULL.", __func__);
457 curvw = vd->vd_curwindow;
459 /* Check if virtual terminal is locked */
460 if (curvw->vw_flags & VWF_VTYLOCK)
463 /* Check if switch already in progress */
464 if (curvw->vw_flags & VWF_SWWAIT_REL) {
465 /* Check if switching to same window */
466 if (curvw->vw_switch_to == vw) {
467 DPRINTF(30, "%s: Switch in progress to same vw.", __func__);
468 return (0); /* success */
470 DPRINTF(30, "%s: Switch in progress to different vw.", __func__);
474 /* Avoid switching to already selected window */
476 DPRINTF(30, "%s: Cannot switch: vw == curvw.", __func__);
477 return (0); /* success */
480 /* Ask current process permission to switch away. */
481 if (curvw->vw_smode.mode == VT_PROCESS) {
482 DPRINTF(30, "%s: VT_PROCESS ", __func__);
483 if (vt_proc_alive(curvw) == FALSE) {
484 DPRINTF(30, "Dead. Cleaning.");
487 DPRINTF(30, "%s: Signaling process.\n", __func__);
488 /* Alive, try to ask him. */
489 ret = vt_window_preswitch(vw, curvw);
490 /* Wait for process answer or timeout. */
496 ret = vt_late_window_switch(vw);
500 /* Switch window ignoring process locking. */
502 vt_window_switch(struct vt_window *vw)
504 struct vt_device *vd = vw->vw_device;
505 struct vt_window *curvw = vd->vd_curwindow;
514 if (!(vw->vw_flags & (VWF_OPENED|VWF_CONSOLE))) {
519 vt_suspend_flush_timer(vd);
521 vd->vd_curwindow = vw;
522 vd->vd_flags |= VDF_INVALID;
523 cv_broadcast(&vd->vd_winswitch);
526 if (vd->vd_driver->vd_postswitch)
527 vd->vd_driver->vd_postswitch(vd);
529 vt_resume_flush_timer(vd, 0);
531 /* Restore per-window keyboard mode. */
533 kbd = kbd_get_keyboard(vd->vd_keyboard);
535 if (curvw->vw_kbdmode == K_XLATE)
536 vt_save_kbd_state(curvw, kbd);
538 vt_update_kbd_mode(vw, kbd);
539 vt_update_kbd_state(vw, kbd);
542 DPRINTF(10, "%s(ttyv%d) done\n", __func__, vw->vw_number);
548 vt_termsize(struct vt_device *vd, struct vt_font *vf, term_pos_t *size)
551 size->tp_row = vd->vd_height;
552 size->tp_col = vd->vd_width;
554 size->tp_row /= vf->vf_height;
555 size->tp_col /= vf->vf_width;
560 vt_winsize(struct vt_device *vd, struct vt_font *vf, struct winsize *size)
563 size->ws_row = size->ws_ypixel = vd->vd_height;
564 size->ws_col = size->ws_xpixel = vd->vd_width;
566 size->ws_row /= vf->vf_height;
567 size->ws_col /= vf->vf_width;
572 vt_compute_drawable_area(struct vt_window *vw)
574 struct vt_device *vd;
579 if (vw->vw_font == NULL) {
580 vw->vw_draw_area.tr_begin.tp_col = 0;
581 vw->vw_draw_area.tr_begin.tp_row = 0;
582 vw->vw_draw_area.tr_end.tp_col = vd->vd_width;
583 vw->vw_draw_area.tr_end.tp_row = vd->vd_height;
590 * Compute the drawable area, so that the text is centered on
594 vw->vw_draw_area.tr_begin.tp_col = (vd->vd_width % vf->vf_width) / 2;
595 vw->vw_draw_area.tr_begin.tp_row = (vd->vd_height % vf->vf_height) / 2;
596 vw->vw_draw_area.tr_end.tp_col = vw->vw_draw_area.tr_begin.tp_col +
597 vd->vd_width / vf->vf_width * vf->vf_width;
598 vw->vw_draw_area.tr_end.tp_row = vw->vw_draw_area.tr_begin.tp_row +
599 vd->vd_height / vf->vf_height * vf->vf_height;
603 vt_scroll(struct vt_window *vw, int offset, int whence)
608 if ((vw->vw_flags & VWF_SCROLL) == 0)
611 vt_termsize(vw->vw_device, vw->vw_font, &size);
613 diff = vthistory_seek(&vw->vw_buf, offset, whence);
615 vw->vw_device->vd_flags |= VDF_INVALID;
616 vt_resume_flush_timer(vw->vw_device, 0);
620 vt_machine_kbdevent(int c)
624 case SPCLKEY | DBG: /* kbdmap(5) keyword `debug`. */
626 kdb_enter(KDB_WHY_BREAK, "manual escape to debugger");
628 case SPCLKEY | HALT: /* kbdmap(5) keyword `halt`. */
630 shutdown_nice(RB_HALT);
632 case SPCLKEY | PASTE: /* kbdmap(5) keyword `paste`. */
633 #ifndef SC_NO_CUTPASTE
634 /* Insert text from cut-paste buffer. */
638 case SPCLKEY | PDWN: /* kbdmap(5) keyword `pdwn`. */
640 shutdown_nice(RB_HALT|RB_POWEROFF);
642 case SPCLKEY | PNC: /* kbdmap(5) keyword `panic`. */
644 * Request to immediate panic if sysctl
645 * kern.vt.enable_panic_key allow it.
648 panic("Forced by the panic key");
650 case SPCLKEY | RBT: /* kbdmap(5) keyword `boot`. */
652 shutdown_nice(RB_AUTOBOOT);
654 case SPCLKEY | SPSC: /* kbdmap(5) keyword `spsc`. */
655 /* Force activatation/deactivation of the screen saver. */
658 case SPCLKEY | STBY: /* XXX Not present in kbdcontrol parser. */
659 /* Put machine into Stand-By mode. */
660 power_pm_suspend(POWER_SLEEP_STATE_STANDBY);
662 case SPCLKEY | SUSP: /* kbdmap(5) keyword `susp`. */
663 /* Suspend machine. */
664 power_pm_suspend(POWER_SLEEP_STATE_SUSPEND);
672 vt_scrollmode_kbdevent(struct vt_window *vw, int c, int console)
674 struct vt_device *vd;
678 /* Only special keys handled in ScrollLock mode */
679 if ((c & SPCLKEY) == 0)
685 if (c >= F_SCR && c <= MIN(L_SCR, F_SCR + VT_MAXWINDOWS - 1)) {
686 vw = vd->vd_windows[c - F_SCR];
687 vt_proc_window_switch(vw);
695 /* Turn scrolling off. */
696 vt_scroll(vw, 0, VHS_END);
697 VTBUF_SLCK_DISABLE(&vw->vw_buf);
698 vw->vw_flags &= ~VWF_SCROLL;
701 case FKEY | F(49): /* Home key. */
702 vt_scroll(vw, 0, VHS_SET);
704 case FKEY | F(50): /* Arrow up. */
705 vt_scroll(vw, -1, VHS_CUR);
707 case FKEY | F(51): /* Page up. */
708 vt_termsize(vd, vw->vw_font, &size);
709 vt_scroll(vw, -size.tp_row, VHS_CUR);
711 case FKEY | F(57): /* End key. */
712 vt_scroll(vw, 0, VHS_END);
714 case FKEY | F(58): /* Arrow down. */
715 vt_scroll(vw, 1, VHS_CUR);
717 case FKEY | F(59): /* Page down. */
718 vt_termsize(vd, vw->vw_font, &size);
719 vt_scroll(vw, size.tp_row, VHS_CUR);
728 vt_processkey(keyboard_t *kbd, struct vt_device *vd, int c)
730 struct vt_window *vw = vd->vd_curwindow;
732 #if VT_ALT_TO_ESC_HACK
734 switch (c & ~RELKEY) {
735 case (SPCLKEY | RALT):
736 if (vt_enable_altgr != 0)
738 case (SPCLKEY | LALT):
739 vd->vd_kbstate &= ~ALKED;
741 /* Other keys ignored for RELKEY event. */
744 switch (c & ~RELKEY) {
745 case (SPCLKEY | RALT):
746 if (vt_enable_altgr != 0)
748 case (SPCLKEY | LALT):
749 vd->vd_kbstate |= ALKED;
754 /* Other keys ignored for RELKEY event. */
758 if (vt_machine_kbdevent(c))
761 if (vw->vw_flags & VWF_SCROLL) {
762 vt_scrollmode_kbdevent(vw, c, 0/* Not a console */);
763 /* Scroll mode keys handled, nothing to do more. */
770 if (c >= F_SCR && c <= MIN(L_SCR, F_SCR + VT_MAXWINDOWS - 1)) {
771 vw = vd->vd_windows[c - F_SCR];
772 vt_proc_window_switch(vw);
778 /* Switch to next VT. */
779 c = (vw->vw_number + 1) % VT_MAXWINDOWS;
780 vw = vd->vd_windows[c];
781 vt_proc_window_switch(vw);
784 /* Switch to previous VT. */
785 c = (vw->vw_number + VT_MAXWINDOWS - 1) % VT_MAXWINDOWS;
786 vw = vd->vd_windows[c];
787 vt_proc_window_switch(vw);
790 vt_save_kbd_state(vw, kbd);
792 if (vw->vw_kbdstate & SLKED) {
793 /* Turn scrolling on. */
794 vw->vw_flags |= VWF_SCROLL;
795 VTBUF_SLCK_ENABLE(&vw->vw_buf);
797 /* Turn scrolling off. */
798 vw->vw_flags &= ~VWF_SCROLL;
799 VTBUF_SLCK_DISABLE(&vw->vw_buf);
800 vt_scroll(vw, 0, VHS_END);
805 case FKEY | F(1): case FKEY | F(2): case FKEY | F(3):
806 case FKEY | F(4): case FKEY | F(5): case FKEY | F(6):
807 case FKEY | F(7): case FKEY | F(8): case FKEY | F(9):
808 case FKEY | F(10): case FKEY | F(11): case FKEY | F(12):
809 /* F1 through F12 keys. */
810 terminal_input_special(vw->vw_terminal,
811 TKEY_F1 + c - (FKEY | F(1)));
813 case FKEY | F(49): /* Home key. */
814 terminal_input_special(vw->vw_terminal, TKEY_HOME);
816 case FKEY | F(50): /* Arrow up. */
817 terminal_input_special(vw->vw_terminal, TKEY_UP);
819 case FKEY | F(51): /* Page up. */
820 terminal_input_special(vw->vw_terminal, TKEY_PAGE_UP);
822 case FKEY | F(53): /* Arrow left. */
823 terminal_input_special(vw->vw_terminal, TKEY_LEFT);
825 case FKEY | F(55): /* Arrow right. */
826 terminal_input_special(vw->vw_terminal, TKEY_RIGHT);
828 case FKEY | F(57): /* End key. */
829 terminal_input_special(vw->vw_terminal, TKEY_END);
831 case FKEY | F(58): /* Arrow down. */
832 terminal_input_special(vw->vw_terminal, TKEY_DOWN);
834 case FKEY | F(59): /* Page down. */
835 terminal_input_special(vw->vw_terminal, TKEY_PAGE_DOWN);
837 case FKEY | F(60): /* Insert key. */
838 terminal_input_special(vw->vw_terminal, TKEY_INSERT);
840 case FKEY | F(61): /* Delete key. */
841 terminal_input_special(vw->vw_terminal, TKEY_DELETE);
844 } else if (KEYFLAGS(c) == 0) {
845 /* Don't do UTF-8 conversion when doing raw mode. */
846 if (vw->vw_kbdmode == K_XLATE) {
847 #if VT_ALT_TO_ESC_HACK
848 if (vd->vd_kbstate & ALKED) {
850 * Prepend ESC sequence if one of ALT keys down.
852 terminal_input_char(vw->vw_terminal, 0x1b);
856 kdb_alt_break(c, &vd->vd_altbrk);
858 terminal_input_char(vw->vw_terminal, KEYCHAR(c));
860 terminal_input_raw(vw->vw_terminal, c);
866 vt_kbdevent(keyboard_t *kbd, int event, void *arg)
868 struct vt_device *vd = arg;
874 case KBDIO_UNLOADING:
876 vd->vd_keyboard = -1;
877 kbd_release(kbd, (void *)vd);
884 while ((c = kbdd_read_char(kbd, 0)) != NOKEY)
885 vt_processkey(kbd, vd, c);
891 vt_allocate_keyboard(struct vt_device *vd)
897 idx0 = kbd_allocate("kbdmux", -1, vd, vt_kbdevent, vd);
899 DPRINTF(20, "%s: kbdmux allocated, idx = %d\n", __func__, idx0);
900 k0 = kbd_get_keyboard(idx0);
902 for (idx = kbd_find_keyboard2("*", -1, 0);
904 idx = kbd_find_keyboard2("*", -1, idx + 1)) {
905 k = kbd_get_keyboard(idx);
907 if (idx == idx0 || KBD_IS_BUSY(k))
910 bzero(&ki, sizeof(ki));
911 strncpy(ki.kb_name, k->kb_name, sizeof(ki.kb_name));
912 ki.kb_name[sizeof(ki.kb_name) - 1] = '\0';
913 ki.kb_unit = k->kb_unit;
915 kbdd_ioctl(k0, KBADDKBD, (caddr_t) &ki);
918 DPRINTF(20, "%s: no kbdmux allocated\n", __func__);
919 idx0 = kbd_allocate("*", -1, vd, vt_kbdevent, vd);
921 DPRINTF(10, "%s: No keyboard found.\n", __func__);
925 vd->vd_keyboard = idx0;
926 DPRINTF(20, "%s: vd_keyboard = %d\n", __func__, vd->vd_keyboard);
932 vtterm_bell(struct terminal *tm)
934 struct vt_window *vw = tm->tm_softc;
935 struct vt_device *vd = vw->vw_device;
937 if (vd->vd_flags & VDF_QUIET_BELL)
940 sysbeep(1193182 / VT_BELLPITCH, VT_BELLDURATION);
944 vtterm_beep(struct terminal *tm, u_int param)
948 if ((param == 0) || ((param & 0xffff) == 0)) {
953 period = ((param >> 16) & 0xffff) * hz / 1000;
954 freq = 1193182 / (param & 0xffff);
956 sysbeep(freq, period);
960 vtterm_cursor(struct terminal *tm, const term_pos_t *p)
962 struct vt_window *vw = tm->tm_softc;
964 vtbuf_cursor_position(&vw->vw_buf, p);
965 vt_resume_flush_timer(vw->vw_device, 0);
969 vtterm_putchar(struct terminal *tm, const term_pos_t *p, term_char_t c)
971 struct vt_window *vw = tm->tm_softc;
973 vtbuf_putchar(&vw->vw_buf, p, c);
974 vt_resume_flush_timer(vw->vw_device, 0);
978 vtterm_fill(struct terminal *tm, const term_rect_t *r, term_char_t c)
980 struct vt_window *vw = tm->tm_softc;
982 vtbuf_fill_locked(&vw->vw_buf, r, c);
983 vt_resume_flush_timer(vw->vw_device, 0);
987 vtterm_copy(struct terminal *tm, const term_rect_t *r,
990 struct vt_window *vw = tm->tm_softc;
992 vtbuf_copy(&vw->vw_buf, r, p);
993 vt_resume_flush_timer(vw->vw_device, 0);
997 vtterm_param(struct terminal *tm, int cmd, unsigned int arg)
999 struct vt_window *vw = tm->tm_softc;
1003 vtbuf_cursor_visibility(&vw->vw_buf, arg);
1004 vt_resume_flush_timer(vw->vw_device, 0);
1007 vw->vw_mouse_level = arg;
1013 vt_determine_colors(term_char_t c, int cursor,
1014 term_color_t *fg, term_color_t *bg)
1021 *fg = TCHAR_FGCOLOR(c);
1022 if (TCHAR_FORMAT(c) & TF_BOLD)
1023 *fg = TCOLOR_LIGHT(*fg);
1024 *bg = TCHAR_BGCOLOR(c);
1026 if (TCHAR_FORMAT(c) & TF_REVERSE)
1038 #ifndef SC_NO_CUTPASTE
1040 vt_is_cursor_in_area(const struct vt_device *vd, const term_rect_t *area)
1042 unsigned int mx, my;
1045 * We use the cursor position saved during the current refresh,
1046 * in case the cursor moved since.
1048 mx = vd->vd_mx_drawn + vd->vd_curwindow->vw_draw_area.tr_begin.tp_col;
1049 my = vd->vd_my_drawn + vd->vd_curwindow->vw_draw_area.tr_begin.tp_row;
1051 if (mx >= area->tr_end.tp_col ||
1052 mx + vd->vd_mcursor->width <= area->tr_begin.tp_col ||
1053 my >= area->tr_end.tp_row ||
1054 my + vd->vd_mcursor->height <= area->tr_begin.tp_row)
1060 vt_mark_mouse_position_as_dirty(struct vt_device *vd)
1063 struct vt_window *vw;
1067 vw = vd->vd_curwindow;
1070 x = vd->vd_mx_drawn;
1071 y = vd->vd_my_drawn;
1074 area.tr_begin.tp_col = x / vf->vf_width;
1075 area.tr_begin.tp_row = y / vf->vf_height;
1076 area.tr_end.tp_col =
1077 ((x + vd->vd_mcursor->width) / vf->vf_width) + 1;
1078 area.tr_end.tp_row =
1079 ((y + vd->vd_mcursor->height) / vf->vf_height) + 1;
1082 * No font loaded (ie. vt_vga operating in textmode).
1084 * FIXME: This fake area needs to be revisited once the
1085 * mouse cursor is supported in vt_vga's textmode.
1087 area.tr_begin.tp_col = x;
1088 area.tr_begin.tp_row = y;
1089 area.tr_end.tp_col = x + 2;
1090 area.tr_end.tp_row = y + 2;
1093 vtbuf_dirty(&vw->vw_buf, &area);
1098 vt_flush(struct vt_device *vd)
1100 struct vt_window *vw;
1104 #ifndef SC_NO_CUTPASTE
1105 int cursor_was_shown, cursor_moved;
1108 vw = vd->vd_curwindow;
1112 if (vd->vd_flags & VDF_SPLASH || vw->vw_flags & VWF_BUSY)
1116 if (((vd->vd_flags & VDF_TEXTMODE) == 0) && (vf == NULL))
1119 #ifndef SC_NO_CUTPASTE
1120 cursor_was_shown = vd->vd_mshown;
1121 cursor_moved = (vd->vd_mx != vd->vd_mx_drawn ||
1122 vd->vd_my != vd->vd_my_drawn);
1124 /* Check if the cursor should be displayed or not. */
1125 if ((vd->vd_flags & VDF_MOUSECURSOR) && /* Mouse support enabled. */
1126 !(vw->vw_flags & VWF_MOUSE_HIDE) && /* Cursor displayed. */
1127 !kdb_active && panicstr == NULL) { /* DDB inactive. */
1134 * If the cursor changed display state or moved, we must mark
1135 * the old position as dirty, so that it's erased.
1137 if (cursor_was_shown != vd->vd_mshown ||
1138 (vd->vd_mshown && cursor_moved))
1139 vt_mark_mouse_position_as_dirty(vd);
1142 * Save position of the mouse cursor. It's used by backends to
1143 * know where to draw the cursor and during the next refresh to
1144 * erase the previous position.
1146 vd->vd_mx_drawn = vd->vd_mx;
1147 vd->vd_my_drawn = vd->vd_my;
1150 * If the cursor is displayed and has moved since last refresh,
1151 * mark the new position as dirty.
1153 if (vd->vd_mshown && cursor_moved)
1154 vt_mark_mouse_position_as_dirty(vd);
1157 vtbuf_undirty(&vw->vw_buf, &tarea);
1158 vt_termsize(vd, vf, &size);
1160 /* Force a full redraw when the screen contents are invalid. */
1161 if (vd->vd_flags & VDF_INVALID) {
1162 tarea.tr_begin.tp_row = tarea.tr_begin.tp_col = 0;
1163 tarea.tr_end = size;
1165 vd->vd_flags &= ~VDF_INVALID;
1168 if (tarea.tr_begin.tp_col < tarea.tr_end.tp_col) {
1169 vd->vd_driver->vd_bitblt_text(vd, vw, &tarea);
1179 struct vt_device *vd;
1183 /* Update screen if required. */
1184 changed = vt_flush(vd);
1186 /* Schedule for next update. */
1188 vt_schedule_flush(vd, 0);
1190 vd->vd_timer_armed = 0;
1194 vtterm_done(struct terminal *tm)
1196 struct vt_window *vw = tm->tm_softc;
1197 struct vt_device *vd = vw->vw_device;
1199 if (kdb_active || panicstr != NULL) {
1200 /* Switch to the debugger. */
1201 if (vd->vd_curwindow != vw) {
1202 vd->vd_curwindow = vw;
1203 vd->vd_flags |= VDF_INVALID;
1204 if (vd->vd_driver->vd_postswitch)
1205 vd->vd_driver->vd_postswitch(vd);
1207 vd->vd_flags &= ~VDF_SPLASH;
1209 } else if (!(vd->vd_flags & VDF_ASYNC)) {
1216 vtterm_splash(struct vt_device *vd)
1218 vt_axis_t top, left;
1220 /* Display a nice boot splash. */
1221 if (!(vd->vd_flags & VDF_TEXTMODE) && (boothowto & RB_MUTE)) {
1223 top = (vd->vd_height - vt_logo_height) / 2;
1224 left = (vd->vd_width - vt_logo_width) / 2;
1225 switch (vt_logo_depth) {
1227 /* XXX: Unhardcode colors! */
1228 vd->vd_driver->vd_bitblt_bmp(vd, vd->vd_curwindow,
1229 vt_logo_image, NULL, vt_logo_width, vt_logo_height,
1230 left, top, TC_WHITE, TC_BLACK);
1232 vd->vd_flags |= VDF_SPLASH;
1239 vtterm_cnprobe(struct terminal *tm, struct consdev *cp)
1241 struct vt_driver *vtd, **vtdlist, *vtdbest = NULL;
1242 struct vt_window *vw = tm->tm_softc;
1243 struct vt_device *vd = vw->vw_device;
1248 if (!vty_enabled(VTY_VT))
1251 if (vd->vd_flags & VDF_INITIALIZED)
1252 /* Initialization already done. */
1255 SET_FOREACH(vtdlist, vt_drv_set) {
1257 if (vtd->vd_probe == NULL)
1259 if (vtd->vd_probe(vd) == CN_DEAD)
1261 if ((vtdbest == NULL) ||
1262 (vtd->vd_priority > vtdbest->vd_priority))
1265 if (vtdbest == NULL) {
1266 cp->cn_pri = CN_DEAD;
1267 vd->vd_flags |= VDF_DEAD;
1269 vd->vd_driver = vtdbest;
1270 cp->cn_pri = vd->vd_driver->vd_init(vd);
1273 /* Check if driver's vt_init return CN_DEAD. */
1274 if (cp->cn_pri == CN_DEAD) {
1275 vd->vd_flags |= VDF_DEAD;
1278 /* Initialize any early-boot keyboard drivers */
1279 kbd_configure(KB_CONF_PROBE_ONLY);
1281 vd->vd_unit = atomic_fetchadd_int(&vt_unit, 1);
1282 vd->vd_windows[VT_CONSWINDOW] = vw;
1283 sprintf(cp->cn_name, "ttyv%r", VT_UNIT(vw));
1285 /* Attach default font if not in TEXTMODE. */
1286 if ((vd->vd_flags & VDF_TEXTMODE) == 0) {
1287 vw->vw_font = vtfont_ref(&vt_font_default);
1288 vt_compute_drawable_area(vw);
1292 * The original screen size was faked (_VTDEFW x _VTDEFH). Now
1293 * that we have the real viewable size, fix it in the static
1296 if (vd->vd_width != 0 && vd->vd_height != 0)
1297 vt_termsize(vd, vw->vw_font, &vw->vw_buf.vb_scr_size);
1299 vtbuf_init_early(&vw->vw_buf);
1300 vt_winsize(vd, vw->vw_font, &wsz);
1301 c = (boothowto & RB_MUTE) == 0 ? TERMINAL_KERN_ATTR :
1303 attr.ta_format = TCHAR_FORMAT(c);
1304 attr.ta_fgcolor = TCHAR_FGCOLOR(c);
1305 attr.ta_bgcolor = TCHAR_BGCOLOR(c);
1306 terminal_set_winsize_blank(tm, &wsz, 1, &attr);
1308 if (vtdbest != NULL) {
1312 vd->vd_flags |= VDF_INITIALIZED;
1317 vtterm_cngetc(struct terminal *tm)
1319 struct vt_window *vw = tm->tm_softc;
1320 struct vt_device *vd = vw->vw_device;
1324 if (vw->vw_kbdsq && *vw->vw_kbdsq)
1325 return (*vw->vw_kbdsq++);
1327 /* Make sure the splash screen is not there. */
1328 if (vd->vd_flags & VDF_SPLASH) {
1330 vd->vd_flags &= ~VDF_SPLASH;
1331 /* Mark screen as invalid to force update */
1332 vd->vd_flags |= VDF_INVALID;
1336 /* Stripped down keyboard handler. */
1337 kbd = kbd_get_keyboard(vd->vd_keyboard);
1341 /* Force keyboard input mode to K_XLATE */
1342 vw->vw_kbdmode = K_XLATE;
1343 vt_update_kbd_mode(vw, kbd);
1345 /* Switch the keyboard to polling to make it work here. */
1346 kbdd_poll(kbd, TRUE);
1347 c = kbdd_read_char(kbd, 0);
1348 kbdd_poll(kbd, FALSE);
1352 if (vw->vw_flags & VWF_SCROLL) {
1353 vt_scrollmode_kbdevent(vw, c, 1/* Console mode */);
1358 /* Stripped down handling of vt_kbdevent(), without locking, etc. */
1362 vt_save_kbd_state(vw, kbd);
1363 if (vw->vw_kbdstate & SLKED) {
1364 /* Turn scrolling on. */
1365 vw->vw_flags |= VWF_SCROLL;
1366 VTBUF_SLCK_ENABLE(&vw->vw_buf);
1368 /* Turn scrolling off. */
1369 vt_scroll(vw, 0, VHS_END);
1370 vw->vw_flags &= ~VWF_SCROLL;
1371 VTBUF_SLCK_DISABLE(&vw->vw_buf);
1374 /* XXX: KDB can handle history. */
1375 case SPCLKEY | FKEY | F(50): /* Arrow up. */
1376 vw->vw_kbdsq = "\x1b[A";
1378 case SPCLKEY | FKEY | F(58): /* Arrow down. */
1379 vw->vw_kbdsq = "\x1b[B";
1381 case SPCLKEY | FKEY | F(55): /* Arrow right. */
1382 vw->vw_kbdsq = "\x1b[C";
1384 case SPCLKEY | FKEY | F(53): /* Arrow left. */
1385 vw->vw_kbdsq = "\x1b[D";
1389 /* Force refresh to make scrollback work. */
1391 } else if (KEYFLAGS(c) == 0) {
1392 return (KEYCHAR(c));
1395 if (vw->vw_kbdsq && *vw->vw_kbdsq)
1396 return (*vw->vw_kbdsq++);
1402 vtterm_cngrab(struct terminal *tm)
1404 struct vt_device *vd;
1405 struct vt_window *vw;
1412 vt_window_switch(vw);
1414 kbd = kbd_get_keyboard(vd->vd_keyboard);
1418 if (vw->vw_grabbed++ > 0)
1422 * Make sure the keyboard is accessible even when the kbd device
1423 * driver is disabled.
1427 /* We shall always use the keyboard in the XLATE mode here. */
1428 vw->vw_prev_kbdmode = vw->vw_kbdmode;
1429 vw->vw_kbdmode = K_XLATE;
1430 vt_update_kbd_mode(vw, kbd);
1432 kbdd_poll(kbd, TRUE);
1436 vtterm_cnungrab(struct terminal *tm)
1438 struct vt_device *vd;
1439 struct vt_window *vw;
1445 kbd = kbd_get_keyboard(vd->vd_keyboard);
1449 if (--vw->vw_grabbed > 0)
1452 kbdd_poll(kbd, FALSE);
1454 vw->vw_kbdmode = vw->vw_prev_kbdmode;
1455 vt_update_kbd_mode(vw, kbd);
1460 vtterm_opened(struct terminal *tm, int opened)
1462 struct vt_window *vw = tm->tm_softc;
1463 struct vt_device *vd = vw->vw_device;
1466 vd->vd_flags &= ~VDF_SPLASH;
1468 vw->vw_flags |= VWF_OPENED;
1470 vw->vw_flags &= ~VWF_OPENED;
1471 /* TODO: finish ACQ/REL */
1477 vt_set_border(struct vt_window *vw, term_color_t c)
1479 struct vt_device *vd = vw->vw_device;
1481 if (vd->vd_driver->vd_drawrect == NULL)
1485 if (vw->vw_draw_area.tr_begin.tp_row > 0)
1486 vd->vd_driver->vd_drawrect(vd,
1488 vd->vd_width - 1, vw->vw_draw_area.tr_begin.tp_row - 1,
1492 if (vw->vw_draw_area.tr_begin.tp_col > 0)
1493 vd->vd_driver->vd_drawrect(vd,
1495 vw->vw_draw_area.tr_begin.tp_col - 1, vd->vd_height - 1,
1499 if (vw->vw_draw_area.tr_end.tp_col < vd->vd_width)
1500 vd->vd_driver->vd_drawrect(vd,
1501 vw->vw_draw_area.tr_end.tp_col - 1, 0,
1502 vd->vd_width - 1, vd->vd_height - 1,
1506 if (vw->vw_draw_area.tr_end.tp_row < vd->vd_height)
1507 vd->vd_driver->vd_drawrect(vd,
1508 0, vw->vw_draw_area.tr_end.tp_row - 1,
1509 vd->vd_width - 1, vd->vd_height - 1,
1516 vt_change_font(struct vt_window *vw, struct vt_font *vf)
1518 struct vt_device *vd = vw->vw_device;
1519 struct terminal *tm = vw->vw_terminal;
1526 * Changing fonts is a little tricky. We must prevent
1527 * simultaneous access to the device, so we must stop
1528 * the display timer and the terminal from accessing.
1529 * We need to switch fonts and grow our screen buffer.
1531 * XXX: Right now the code uses terminal_mute() to
1532 * prevent data from reaching the console driver while
1533 * resizing the screen buffer. This isn't elegant...
1537 if (vw->vw_flags & VWF_BUSY) {
1538 /* Another process is changing the font. */
1542 vw->vw_flags |= VWF_BUSY;
1545 vt_termsize(vd, vf, &size);
1546 vt_winsize(vd, vf, &wsz);
1548 /* Grow the screen buffer and terminal. */
1549 terminal_mute(tm, 1);
1550 vtbuf_grow(&vw->vw_buf, &size, vw->vw_buf.vb_history_size);
1551 terminal_set_winsize_blank(tm, &wsz, 0, NULL);
1552 terminal_set_cursor(tm, &vw->vw_buf.vb_cursor);
1553 terminal_mute(tm, 0);
1555 /* Actually apply the font to the current window. */
1557 if (vw->vw_font != vf && vw->vw_font != NULL && vf != NULL) {
1559 * In case vt_change_font called to update size we don't need
1560 * to update font link.
1562 vtfont_unref(vw->vw_font);
1563 vw->vw_font = vtfont_ref(vf);
1567 * Compute the drawable area and move the mouse cursor inside
1568 * it, in case the new area is smaller than the previous one.
1570 vt_compute_drawable_area(vw);
1571 vd->vd_mx = min(vd->vd_mx,
1572 vw->vw_draw_area.tr_end.tp_col -
1573 vw->vw_draw_area.tr_begin.tp_col - 1);
1574 vd->vd_my = min(vd->vd_my,
1575 vw->vw_draw_area.tr_end.tp_row -
1576 vw->vw_draw_area.tr_begin.tp_row - 1);
1578 /* Force a full redraw the next timer tick. */
1579 if (vd->vd_curwindow == vw) {
1580 vt_set_border(vw, TC_BLACK);
1581 vd->vd_flags |= VDF_INVALID;
1582 vt_resume_flush_timer(vw->vw_device, 0);
1584 vw->vw_flags &= ~VWF_BUSY;
1590 vt_proc_alive(struct vt_window *vw)
1594 if (vw->vw_smode.mode != VT_PROCESS)
1598 if ((p = pfind(vw->vw_pid)) != NULL)
1600 if (vw->vw_proc == p)
1603 vw->vw_smode.mode = VT_AUTO;
1604 DPRINTF(1, "vt controlling process %d died\n", vw->vw_pid);
1611 signal_vt_rel(struct vt_window *vw)
1614 if (vw->vw_smode.mode != VT_PROCESS)
1616 if (vw->vw_proc == NULL || vt_proc_alive(vw) == FALSE) {
1621 vw->vw_flags |= VWF_SWWAIT_REL;
1622 PROC_LOCK(vw->vw_proc);
1623 kern_psignal(vw->vw_proc, vw->vw_smode.relsig);
1624 PROC_UNLOCK(vw->vw_proc);
1625 DPRINTF(1, "sending relsig to %d\n", vw->vw_pid);
1630 signal_vt_acq(struct vt_window *vw)
1633 if (vw->vw_smode.mode != VT_PROCESS)
1635 if (vw == vw->vw_device->vd_windows[VT_CONSWINDOW])
1636 cnavailable(vw->vw_terminal->consdev, FALSE);
1637 if (vw->vw_proc == NULL || vt_proc_alive(vw) == FALSE) {
1642 vw->vw_flags |= VWF_SWWAIT_ACQ;
1643 PROC_LOCK(vw->vw_proc);
1644 kern_psignal(vw->vw_proc, vw->vw_smode.acqsig);
1645 PROC_UNLOCK(vw->vw_proc);
1646 DPRINTF(1, "sending acqsig to %d\n", vw->vw_pid);
1651 finish_vt_rel(struct vt_window *vw, int release, int *s)
1654 if (vw->vw_flags & VWF_SWWAIT_REL) {
1655 vw->vw_flags &= ~VWF_SWWAIT_REL;
1657 callout_drain(&vw->vw_proc_dead_timer);
1658 vt_late_window_switch(vw->vw_switch_to);
1666 finish_vt_acq(struct vt_window *vw)
1669 if (vw->vw_flags & VWF_SWWAIT_ACQ) {
1670 vw->vw_flags &= ~VWF_SWWAIT_ACQ;
1676 #ifndef SC_NO_CUTPASTE
1678 vt_mouse_terminput_button(struct vt_device *vd, int button)
1680 struct vt_window *vw;
1682 char mouseb[6] = "\x1B[M";
1685 vw = vd->vd_curwindow;
1688 /* Translate to char position. */
1689 x = vd->vd_mx / vf->vf_width;
1690 y = vd->vd_my / vf->vf_height;
1691 /* Avoid overflow. */
1692 x = MIN(x, 255 - '!');
1693 y = MIN(y, 255 - '!');
1695 mouseb[3] = ' ' + button;
1696 mouseb[4] = '!' + x;
1697 mouseb[5] = '!' + y;
1699 for (i = 0; i < sizeof(mouseb); i++)
1700 terminal_input_char(vw->vw_terminal, mouseb[i]);
1704 vt_mouse_terminput(struct vt_device *vd, int type, int x, int y, int event,
1709 case MOUSE_BUTTON_EVENT:
1711 /* Mouse button pressed. */
1712 if (event & MOUSE_BUTTON1DOWN)
1713 vt_mouse_terminput_button(vd, 0);
1714 if (event & MOUSE_BUTTON2DOWN)
1715 vt_mouse_terminput_button(vd, 1);
1716 if (event & MOUSE_BUTTON3DOWN)
1717 vt_mouse_terminput_button(vd, 2);
1719 /* Mouse button released. */
1720 vt_mouse_terminput_button(vd, 3);
1724 case MOUSE_MOTION_EVENT:
1725 if (mouse->u.data.z < 0) {
1727 sc_mouse_input_button(vd, 64);
1728 } else if (mouse->u.data.z > 0) {
1730 sc_mouse_input_button(vd, 65);
1743 len = VD_PASTEBUFLEN(main_vd);
1744 buf = VD_PASTEBUF(main_vd);
1745 len /= sizeof(term_char_t);
1746 for (i = 0; i < len; i++) {
1749 terminal_input_char(main_vd->vd_curwindow->vw_terminal,
1755 vt_mouse_event(int type, int x, int y, int event, int cnt, int mlevel)
1757 struct vt_device *vd;
1758 struct vt_window *vw;
1764 vw = vd->vd_curwindow;
1768 if (vw->vw_flags & (VWF_MOUSE_HIDE | VWF_GRAPHICS))
1770 * Either the mouse is disabled, or the window is in
1771 * "graphics mode". The graphics mode is usually set by
1772 * an X server, using the KDSETMODE ioctl.
1776 if (vf == NULL) /* Text mode. */
1780 * TODO: add flag about pointer position changed, to not redraw chars
1781 * under mouse pointer when nothing changed.
1784 if (vw->vw_mouse_level > 0)
1785 vt_mouse_terminput(vd, type, x, y, event, cnt);
1789 case MOUSE_MOTION_EVENT:
1794 vt_termsize(vd, vf, &size);
1799 x = MIN(x, (size.tp_col * vf->vf_width) - 1);
1800 y = MIN(y, (size.tp_row * vf->vf_height) - 1);
1804 if (vd->vd_mstate & MOUSE_BUTTON1DOWN)
1805 vtbuf_set_mark(&vw->vw_buf, VTB_MARK_MOVE,
1806 vd->vd_mx / vf->vf_width,
1807 vd->vd_my / vf->vf_height);
1809 vt_resume_flush_timer(vw->vw_device, 0);
1811 case MOUSE_BUTTON_EVENT:
1819 case MOUSE_BUTTON1DOWN:
1822 mark = VTB_MARK_END;
1824 case 1: /* single click: start cut operation */
1825 mark = VTB_MARK_START;
1827 case 2: /* double click: cut a word */
1828 mark = VTB_MARK_WORD;
1830 case 3: /* triple click: cut a line */
1831 mark = VTB_MARK_ROW;
1835 case VT_MOUSE_PASTEBUTTON:
1844 case VT_MOUSE_EXTENDBUTTON:
1847 if (!(vd->vd_mstate & MOUSE_BUTTON1DOWN))
1848 mark = VTB_MARK_EXTEND;
1853 mark = VTB_MARK_EXTEND;
1861 /* Save buttons state. */
1863 vd->vd_mstate |= event;
1865 vd->vd_mstate &= ~event;
1867 if (vtbuf_set_mark(&vw->vw_buf, mark, vd->vd_mx / vf->vf_width,
1868 vd->vd_my / vf->vf_height) == 1) {
1870 * We have something marked to copy, so update pointer to
1871 * window with selection.
1873 vt_resume_flush_timer(vw->vw_device, 0);
1879 case VTB_MARK_EXTEND:
1882 /* Other types of mark do not require to copy data. */
1886 /* Get current selection size in bytes. */
1887 len = vtbuf_get_marked_len(&vw->vw_buf);
1891 /* Reallocate buffer only if old one is too small. */
1892 if (len > VD_PASTEBUFSZ(vd)) {
1893 VD_PASTEBUF(vd) = realloc(VD_PASTEBUF(vd), len, M_VT,
1895 /* Update buffer size. */
1896 VD_PASTEBUFSZ(vd) = len;
1898 /* Request copy/paste buffer data, no more than `len' */
1899 vtbuf_extract_marked(&vw->vw_buf, VD_PASTEBUF(vd),
1902 VD_PASTEBUFLEN(vd) = len;
1904 /* XXX VD_PASTEBUF(vd) have to be freed on shutdown/unload. */
1909 vt_mouse_state(int show)
1911 struct vt_device *vd;
1912 struct vt_window *vw;
1915 vw = vd->vd_curwindow;
1919 vw->vw_flags |= VWF_MOUSE_HIDE;
1922 vw->vw_flags &= ~VWF_MOUSE_HIDE;
1926 /* Mark mouse position as dirty. */
1927 vt_mark_mouse_position_as_dirty(vd);
1928 vt_resume_flush_timer(vw->vw_device, 0);
1933 vtterm_mmap(struct terminal *tm, vm_ooffset_t offset, vm_paddr_t * paddr,
1934 int nprot, vm_memattr_t *memattr)
1936 struct vt_window *vw = tm->tm_softc;
1937 struct vt_device *vd = vw->vw_device;
1939 if (vd->vd_driver->vd_fb_mmap)
1940 return (vd->vd_driver->vd_fb_mmap(vd, offset, paddr, nprot,
1947 vtterm_ioctl(struct terminal *tm, u_long cmd, caddr_t data,
1950 struct vt_window *vw = tm->tm_softc;
1951 struct vt_device *vd = vw->vw_device;
1954 #if defined(COMPAT_FREEBSD6) || defined(COMPAT_FREEBSD5) || \
1955 defined(COMPAT_FREEBSD4) || defined(COMPAT_43)
1966 cmd = VT_WAITACTIVE;
1992 ival = IOCPARM_IVAL(data);
1993 data = (caddr_t)&ival;
1998 case KDSETRAD: /* set keyboard repeat & delay rates (old) */
1999 if (*(int *)data & ~0x7f)
2004 case GIO_DEADKEYMAP:
2005 case PIO_DEADKEYMAP:
2010 case KDGETREPEAT: /* get keyboard repeat & delay rates */
2011 case KDSETREPEAT: /* set keyboard repeat & delay rates (new) */
2012 case KBADDKBD: /* add/remove keyboard to/from mux */
2017 kbd = kbd_get_keyboard(vd->vd_keyboard);
2019 error = kbdd_ioctl(kbd, cmd, data);
2021 if (error == ENOIOCTL) {
2022 if (cmd == KDGKBTYPE) {
2023 /* always return something? XXX */
2031 case KDGKBSTATE: { /* get keyboard state (locks) */
2034 if (vw == vd->vd_curwindow) {
2036 kbd = kbd_get_keyboard(vd->vd_keyboard);
2038 error = vt_save_kbd_state(vw, kbd);
2045 *(int *)data = vw->vw_kbdstate & LOCK_MASK;
2049 case KDSKBSTATE: { /* set keyboard state (locks) */
2052 state = *(int *)data;
2053 if (state & ~LOCK_MASK)
2056 vw->vw_kbdstate &= ~LOCK_MASK;
2057 vw->vw_kbdstate |= state;
2060 if (vw == vd->vd_curwindow) {
2062 kbd = kbd_get_keyboard(vd->vd_keyboard);
2064 error = vt_update_kbd_state(vw, kbd);
2070 case KDGETLED: { /* get keyboard LED status */
2073 if (vw == vd->vd_curwindow) {
2075 kbd = kbd_get_keyboard(vd->vd_keyboard);
2077 error = vt_save_kbd_leds(vw, kbd);
2084 *(int *)data = vw->vw_kbdstate & LED_MASK;
2088 case KDSETLED: { /* set keyboard LED status */
2091 leds = *(int *)data;
2092 if (leds & ~LED_MASK)
2095 vw->vw_kbdstate &= ~LED_MASK;
2096 vw->vw_kbdstate |= leds;
2099 if (vw == vd->vd_curwindow) {
2101 kbd = kbd_get_keyboard(vd->vd_keyboard);
2103 error = vt_update_kbd_leds(vw, kbd);
2112 if (vw == vd->vd_curwindow) {
2114 kbd = kbd_get_keyboard(vd->vd_keyboard);
2116 error = vt_save_kbd_mode(vw, kbd);
2123 *(int *)data = vw->vw_kbdmode;
2130 mode = *(int *)data;
2135 vw->vw_kbdmode = mode;
2138 if (vw == vd->vd_curwindow) {
2140 kbd = kbd_get_keyboard(vd->vd_keyboard);
2142 error = vt_update_kbd_mode(vw, kbd);
2152 case FBIO_GETWINORG: /* get frame buffer window origin */
2153 case FBIO_GETDISPSTART: /* get display start address */
2154 case FBIO_GETLINEWIDTH: /* get scan line width in bytes */
2155 case FBIO_BLANK: /* blank display */
2156 if (vd->vd_driver->vd_fb_ioctl)
2157 return (vd->vd_driver->vd_fb_ioctl(vd, cmd, data, td));
2159 case CONS_BLANKTIME:
2164 *(int *)data = M_CG640x480;
2166 case CONS_BELLTYPE: /* set bell type sound */
2167 if ((*(int *)data) & CONS_QUIET_BELL)
2168 vd->vd_flags |= VDF_QUIET_BELL;
2170 vd->vd_flags &= ~VDF_QUIET_BELL;
2172 case CONS_GETINFO: {
2173 vid_info_t *vi = (vid_info_t *)data;
2174 if (vi->size != sizeof(struct vid_info))
2177 if (vw == vd->vd_curwindow) {
2178 kbd = kbd_get_keyboard(vd->vd_keyboard);
2180 vt_save_kbd_state(vw, kbd);
2183 vi->m_num = vd->vd_curwindow->vw_number + 1;
2184 vi->mk_keylock = vw->vw_kbdstate & LOCK_MASK;
2185 /* XXX: other fields! */
2189 *(int *)data = 0x200;
2194 case CONS_MOUSECTL: {
2195 mouse_info_t *mouse = (mouse_info_t*)data;
2198 * All the commands except MOUSE_SHOW nd MOUSE_HIDE
2199 * should not be applied to individual TTYs, but only to
2202 switch (mouse->operation) {
2204 if (vd->vd_flags & VDF_MOUSECURSOR) {
2205 vd->vd_flags &= ~VDF_MOUSECURSOR;
2206 #ifndef SC_NO_CUTPASTE
2207 vt_mouse_state(VT_MOUSE_HIDE);
2212 if (!(vd->vd_flags & VDF_MOUSECURSOR)) {
2213 vd->vd_flags |= VDF_MOUSECURSOR;
2214 vd->vd_mx = vd->vd_width / 2;
2215 vd->vd_my = vd->vd_height / 2;
2216 #ifndef SC_NO_CUTPASTE
2217 vt_mouse_state(VT_MOUSE_SHOW);
2228 if (vd->vd_flags & VDF_TEXTMODE)
2231 error = vtfont_load((void *)data, &vf);
2235 error = vt_change_font(vw, vf);
2239 case PIO_VFONT_DEFAULT: {
2240 /* Reset to default font. */
2241 error = vt_change_font(vw, &vt_font_default);
2245 scrmap_t *sm = (scrmap_t *)data;
2247 /* We don't have screen maps, so return a handcrafted one. */
2248 for (i = 0; i < 256; i++)
2254 * FIXME: This implementation is incomplete compared to
2257 switch (*(int *)data) {
2261 vw->vw_flags &= ~VWF_GRAPHICS;
2264 vw->vw_flags |= VWF_GRAPHICS;
2268 case KDENABIO: /* allow io operations */
2269 error = priv_check(td, PRIV_IO);
2272 error = securelevel_gt(td->td_ucred, 0);
2275 #if defined(__i386__)
2276 td->td_frame->tf_eflags |= PSL_IOPL;
2277 #elif defined(__amd64__)
2278 td->td_frame->tf_rflags |= PSL_IOPL;
2281 case KDDISABIO: /* disallow io operations (default) */
2282 #if defined(__i386__)
2283 td->td_frame->tf_eflags &= ~PSL_IOPL;
2284 #elif defined(__amd64__)
2285 td->td_frame->tf_rflags &= ~PSL_IOPL;
2288 case KDMKTONE: /* sound the bell */
2289 vtterm_beep(tm, *(u_int *)data);
2291 case KIOCSOUND: /* make tone (*data) hz */
2294 case CONS_SETKBD: /* set the new keyboard */
2297 if (vd->vd_keyboard != *(int *)data) {
2298 kbd = kbd_get_keyboard(*(int *)data);
2303 i = kbd_allocate(kbd->kb_name, kbd->kb_unit,
2304 (void *)vd, vt_kbdevent, vd);
2306 if (vd->vd_keyboard != -1) {
2307 vt_save_kbd_state(vd->vd_curwindow, kbd);
2308 kbd_release(kbd, (void *)vd);
2310 kbd = kbd_get_keyboard(i);
2311 vd->vd_keyboard = i;
2313 vt_update_kbd_mode(vd->vd_curwindow, kbd);
2314 vt_update_kbd_state(vd->vd_curwindow, kbd);
2316 error = EPERM; /* XXX */
2321 case CONS_RELKBD: /* release the current keyboard */
2324 if (vd->vd_keyboard != -1) {
2325 kbd = kbd_get_keyboard(vd->vd_keyboard);
2330 vt_save_kbd_state(vd->vd_curwindow, kbd);
2331 error = kbd_release(kbd, (void *)vd);
2333 vd->vd_keyboard = -1;
2340 win = *(int *)data - 1;
2341 DPRINTF(5, "%s%d: VT_ACTIVATE ttyv%d ", SC_DRIVER_NAME,
2343 if ((win >= VT_MAXWINDOWS) || (win < 0))
2345 return (vt_proc_window_switch(vd->vd_windows[win]));
2348 *(int *)data = vd->vd_curwindow->vw_number + 1;
2351 *(int *)data = vw->vw_number + 1;
2354 /* TODO: Check current state, switching can be in progress. */
2355 if ((*(int *)data) == 0x01)
2356 vw->vw_flags |= VWF_VTYLOCK;
2357 else if ((*(int *)data) == 0x02)
2358 vw->vw_flags &= ~VWF_VTYLOCK;
2364 for (i = 0; i < VT_MAXWINDOWS; i++) {
2365 vw = vd->vd_windows[i];
2368 if (!(vw->vw_flags & VWF_OPENED)) {
2369 *(int *)data = vw->vw_number + 1;
2376 case VT_WAITACTIVE: {
2381 idx = *(unsigned int *)data;
2382 if (idx > VT_MAXWINDOWS)
2385 vw = vd->vd_windows[idx - 1];
2388 while (vd->vd_curwindow != vw && error == 0)
2389 error = cv_wait_sig(&vd->vd_winswitch, &vd->vd_lock);
2393 case VT_SETMODE: { /* set screen switcher mode */
2394 struct vt_mode *mode;
2397 mode = (struct vt_mode *)data;
2398 DPRINTF(5, "%s%d: VT_SETMODE ", SC_DRIVER_NAME, VT_UNIT(vw));
2399 if (vw->vw_smode.mode == VT_PROCESS) {
2400 p1 = pfind(vw->vw_pid);
2401 if (vw->vw_proc == p1 && vw->vw_proc != td->td_proc) {
2404 DPRINTF(5, "error EPERM\n");
2410 if (mode->mode == VT_AUTO) {
2411 vw->vw_smode.mode = VT_AUTO;
2414 DPRINTF(5, "VT_AUTO, ");
2415 if (vw == vw->vw_device->vd_windows[VT_CONSWINDOW])
2416 cnavailable(vw->vw_terminal->consdev, TRUE);
2417 /* were we in the middle of the vty switching process? */
2418 if (finish_vt_rel(vw, TRUE, &s) == 0)
2419 DPRINTF(5, "reset WAIT_REL, ");
2420 if (finish_vt_acq(vw) == 0)
2421 DPRINTF(5, "reset WAIT_ACQ, ");
2423 } else if (mode->mode == VT_PROCESS) {
2424 if (!ISSIGVALID(mode->relsig) ||
2425 !ISSIGVALID(mode->acqsig) ||
2426 !ISSIGVALID(mode->frsig)) {
2427 DPRINTF(5, "error EINVAL\n");
2430 DPRINTF(5, "VT_PROCESS %d, ", td->td_proc->p_pid);
2431 bcopy(data, &vw->vw_smode, sizeof(struct vt_mode));
2432 vw->vw_proc = td->td_proc;
2433 vw->vw_pid = vw->vw_proc->p_pid;
2434 if (vw == vw->vw_device->vd_windows[VT_CONSWINDOW])
2435 cnavailable(vw->vw_terminal->consdev, FALSE);
2437 DPRINTF(5, "VT_SETMODE failed, unknown mode %d\n",
2444 case VT_GETMODE: /* get screen switcher mode */
2445 bcopy(&vw->vw_smode, data, sizeof(struct vt_mode));
2448 case VT_RELDISP: /* screen switcher ioctl */
2450 * This must be the current vty which is in the VT_PROCESS
2453 if ((vw != vd->vd_curwindow) || (vw->vw_smode.mode !=
2457 /* ...and this process is controlling it. */
2458 if (vw->vw_proc != td->td_proc) {
2462 switch(*(int *)data) {
2463 case VT_FALSE: /* user refuses to release screen, abort */
2464 if ((error = finish_vt_rel(vw, FALSE, &s)) == 0)
2465 DPRINTF(5, "%s%d: VT_RELDISP: VT_FALSE\n",
2466 SC_DRIVER_NAME, VT_UNIT(vw));
2468 case VT_TRUE: /* user has released screen, go on */
2469 /* finish_vt_rel(..., TRUE, ...) should not be locked */
2470 if (vw->vw_flags & VWF_SWWAIT_REL) {
2471 if ((error = finish_vt_rel(vw, TRUE, &s)) == 0)
2472 DPRINTF(5, "%s%d: VT_RELDISP: VT_TRUE\n",
2473 SC_DRIVER_NAME, VT_UNIT(vw));
2478 case VT_ACKACQ: /* acquire acknowledged, switch completed */
2479 if ((error = finish_vt_acq(vw)) == 0)
2480 DPRINTF(5, "%s%d: VT_RELDISP: VT_ACKACQ\n",
2481 SC_DRIVER_NAME, VT_UNIT(vw));
2492 static struct vt_window *
2493 vt_allocate_window(struct vt_device *vd, unsigned int window)
2495 struct vt_window *vw;
2496 struct terminal *tm;
2500 vw = malloc(sizeof *vw, M_VT, M_WAITOK|M_ZERO);
2502 vw->vw_number = window;
2503 vw->vw_kbdmode = K_XLATE;
2505 if ((vd->vd_flags & VDF_TEXTMODE) == 0) {
2506 vw->vw_font = vtfont_ref(&vt_font_default);
2507 vt_compute_drawable_area(vw);
2510 vt_termsize(vd, vw->vw_font, &size);
2511 vt_winsize(vd, vw->vw_font, &wsz);
2512 vtbuf_init(&vw->vw_buf, &size);
2514 tm = vw->vw_terminal = terminal_alloc(&vt_termclass, vw);
2515 terminal_set_winsize(tm, &wsz);
2516 vd->vd_windows[window] = vw;
2517 callout_init(&vw->vw_proc_dead_timer, 0);
2523 vt_upgrade(struct vt_device *vd)
2525 struct vt_window *vw;
2527 int register_handlers;
2529 if (!vty_enabled(VTY_VT))
2531 if (main_vd->vd_driver == NULL)
2534 for (i = 0; i < VT_MAXWINDOWS; i++) {
2535 vw = vd->vd_windows[i];
2538 vw = vt_allocate_window(vd, i);
2540 if (!(vw->vw_flags & VWF_READY)) {
2541 callout_init(&vw->vw_proc_dead_timer, 0);
2542 terminal_maketty(vw->vw_terminal, "v%r", VT_UNIT(vw));
2543 vw->vw_flags |= VWF_READY;
2544 if (vw->vw_flags & VWF_CONSOLE) {
2545 /* For existing console window. */
2546 EVENTHANDLER_REGISTER(shutdown_pre_sync,
2547 vt_window_switch, vw, SHUTDOWN_PRI_DEFAULT);
2553 if (vd->vd_curwindow == NULL)
2554 vd->vd_curwindow = vd->vd_windows[VT_CONSWINDOW];
2556 register_handlers = 0;
2557 if (!(vd->vd_flags & VDF_ASYNC)) {
2558 /* Attach keyboard. */
2559 vt_allocate_keyboard(vd);
2561 /* Init 25 Hz timer. */
2562 callout_init_mtx(&vd->vd_timer, &vd->vd_lock, 0);
2564 /* Start timer when everything ready. */
2565 vd->vd_flags |= VDF_ASYNC;
2566 callout_reset(&vd->vd_timer, hz / VT_TIMERFREQ, vt_timer, vd);
2567 vd->vd_timer_armed = 1;
2568 register_handlers = 1;
2573 /* Refill settings with new sizes. */
2576 if (register_handlers) {
2577 /* Register suspend/resume handlers. */
2578 EVENTHANDLER_REGISTER(power_suspend_early, vt_suspend_handler,
2579 vd, EVENTHANDLER_PRI_ANY);
2580 EVENTHANDLER_REGISTER(power_resume, vt_resume_handler, vd,
2581 EVENTHANDLER_PRI_ANY);
2586 vt_resize(struct vt_device *vd)
2588 struct vt_window *vw;
2591 for (i = 0; i < VT_MAXWINDOWS; i++) {
2592 vw = vd->vd_windows[i];
2594 /* Assign default font to window, if not textmode. */
2595 if (!(vd->vd_flags & VDF_TEXTMODE) && vw->vw_font == NULL)
2596 vw->vw_font = vtfont_ref(&vt_font_default);
2599 /* Resize terminal windows */
2600 while (vt_change_font(vw, vw->vw_font) == EBUSY) {
2601 DPRINTF(100, "%s: vt_change_font() is busy, "
2602 "window %d\n", __func__, i);
2608 vt_allocate(struct vt_driver *drv, void *softc)
2610 struct vt_device *vd;
2612 if (!vty_enabled(VTY_VT))
2615 if (main_vd->vd_driver == NULL) {
2616 main_vd->vd_driver = drv;
2617 printf("VT: initialize with new VT driver \"%s\".\n",
2621 * Check if have rights to replace current driver. For example:
2622 * it is bad idea to replace KMS driver with generic VGA one.
2624 if (drv->vd_priority <= main_vd->vd_driver->vd_priority) {
2625 printf("VT: Driver priority %d too low. Current %d\n ",
2626 drv->vd_priority, main_vd->vd_driver->vd_priority);
2629 printf("VT: Replacing driver \"%s\" with new \"%s\".\n",
2630 main_vd->vd_driver->vd_name, drv->vd_name);
2634 if (vd->vd_flags & VDF_ASYNC) {
2635 /* Stop vt_flush periodic task. */
2637 vt_suspend_flush_timer(vd);
2640 * Mute current terminal until we done. vt_change_font (called
2641 * from vt_resize) will unmute it.
2643 terminal_mute(vd->vd_curwindow->vw_terminal, 1);
2647 * Reset VDF_TEXTMODE flag, driver who require that flag (vt_vga) will
2651 vd->vd_flags &= ~VDF_TEXTMODE;
2653 vd->vd_driver = drv;
2654 vd->vd_softc = softc;
2655 vd->vd_driver->vd_init(vd);
2658 /* Update windows sizes and initialize last items. */
2662 if (vd->vd_flags & VDF_SPLASH)
2666 if (vd->vd_flags & VDF_ASYNC) {
2667 /* Allow to put chars now. */
2668 terminal_mute(vd->vd_curwindow->vw_terminal, 0);
2669 /* Rerun timer for screen updates. */
2670 vt_resume_flush_timer(vd, 0);
2674 * Register as console. If it already registered, cnadd() will ignore
2677 termcn_cnregister(vd->vd_windows[VT_CONSWINDOW]->vw_terminal);
2681 vt_suspend_handler(void *priv)
2683 struct vt_device *vd;
2686 if (vd->vd_driver != NULL && vd->vd_driver->vd_suspend != NULL)
2687 vd->vd_driver->vd_suspend(vd);
2691 vt_resume_handler(void *priv)
2693 struct vt_device *vd;
2696 if (vd->vd_driver != NULL && vd->vd_driver->vd_resume != NULL)
2697 vd->vd_driver->vd_resume(vd);
2701 vt_suspend(struct vt_device *vd)
2705 if (vt_suspendswitch == 0)
2707 /* Save current window. */
2708 vd->vd_savedwindow = vd->vd_curwindow;
2709 /* Ask holding process to free window and switch to console window */
2710 vt_proc_window_switch(vd->vd_windows[VT_CONSWINDOW]);
2712 /* Wait for the window switch to complete. */
2715 while (vd->vd_curwindow != vd->vd_windows[VT_CONSWINDOW] && error == 0)
2716 error = cv_wait_sig(&vd->vd_winswitch, &vd->vd_lock);
2721 vt_resume(struct vt_device *vd)
2724 if (vt_suspendswitch == 0)
2726 /* Switch back to saved window, if any */
2727 vt_proc_window_switch(vd->vd_savedwindow);
2728 vd->vd_savedwindow = NULL;