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(enable_bell, 1, "Enable bell");
125 VT_SYSCTL_INT(debug, 0, "vt(9) debug level");
126 VT_SYSCTL_INT(deadtimer, 15, "Time to wait busy process in VT_PROCESS mode");
127 VT_SYSCTL_INT(suspendswitch, 1, "Switch to VT0 before suspend");
129 /* Allow to disable some keyboard combinations. */
130 VT_SYSCTL_INT(kbd_halt, 1, "Enable halt keyboard combination. "
131 "See kbdmap(5) to configure.");
132 VT_SYSCTL_INT(kbd_poweroff, 1, "Enable Power Off keyboard combination. "
133 "See kbdmap(5) to configure.");
134 VT_SYSCTL_INT(kbd_reboot, 1, "Enable reboot keyboard combination. "
135 "See kbdmap(5) to configure (typically Ctrl-Alt-Delete).");
136 VT_SYSCTL_INT(kbd_debug, 1, "Enable key combination to enter debugger. "
137 "See kbdmap(5) to configure (typically Ctrl-Alt-Esc).");
138 VT_SYSCTL_INT(kbd_panic, 0, "Enable request to panic. "
139 "See kbdmap(5) to configure.");
141 static struct vt_device vt_consdev;
142 static unsigned int vt_unit = 0;
143 static MALLOC_DEFINE(M_VT, "vt", "vt device");
144 struct vt_device *main_vd = &vt_consdev;
147 extern unsigned int vt_logo_width;
148 extern unsigned int vt_logo_height;
149 extern unsigned int vt_logo_depth;
150 extern unsigned char vt_logo_image[];
153 extern struct vt_font vt_font_default;
154 #ifndef SC_NO_CUTPASTE
155 extern struct vt_mouse_cursor vt_default_mouse_pointer;
158 static int signal_vt_rel(struct vt_window *);
159 static int signal_vt_acq(struct vt_window *);
160 static int finish_vt_rel(struct vt_window *, int, int *);
161 static int finish_vt_acq(struct vt_window *);
162 static int vt_window_switch(struct vt_window *);
163 static int vt_late_window_switch(struct vt_window *);
164 static int vt_proc_alive(struct vt_window *);
165 static void vt_resize(struct vt_device *);
166 static void vt_update_static(void *);
167 #ifndef SC_NO_CUTPASTE
168 static void vt_mouse_paste(void);
170 static void vt_suspend_handler(void *priv);
171 static void vt_resume_handler(void *priv);
173 SET_DECLARE(vt_drv_set, struct vt_driver);
175 #define _VTDEFH MAX(100, PIXEL_HEIGHT(VT_FB_DEFAULT_HEIGHT))
176 #define _VTDEFW MAX(200, PIXEL_WIDTH(VT_FB_DEFAULT_WIDTH))
178 static struct terminal vt_consterm;
179 static struct vt_window vt_conswindow;
180 static struct vt_device vt_consdev = {
183 .vd_flags = VDF_INVALID,
184 .vd_windows = { [VT_CONSWINDOW] = &vt_conswindow, },
185 .vd_curwindow = &vt_conswindow,
188 #ifndef SC_NO_CUTPASTE
194 .vd_mcursor = &vt_default_mouse_pointer,
195 .vd_mcursor_fg = TC_WHITE,
196 .vd_mcursor_bg = TC_BLACK,
199 static term_char_t vt_constextbuf[(_VTDEFW) * (VBF_DEFAULT_HISTORY_SIZE)];
200 static term_char_t *vt_constextbufrows[VBF_DEFAULT_HISTORY_SIZE];
201 static struct vt_window vt_conswindow = {
202 .vw_number = VT_CONSWINDOW,
203 .vw_flags = VWF_CONSOLE,
205 .vb_buffer = &vt_constextbuf[0],
206 .vb_rows = &vt_constextbufrows[0],
207 .vb_history_size = VBF_DEFAULT_HISTORY_SIZE,
210 .vb_flags = VBF_STATIC,
211 .vb_mark_start = {.tp_row = 0, .tp_col = 0,},
212 .vb_mark_end = {.tp_row = 0, .tp_col = 0,},
218 .vw_device = &vt_consdev,
219 .vw_terminal = &vt_consterm,
220 .vw_kbdmode = K_XLATE,
223 static struct terminal vt_consterm = {
224 .tm_class = &vt_termclass,
225 .tm_softc = &vt_conswindow,
228 static struct consdev vt_consterm_consdev = {
229 .cn_ops = &termcn_cnops,
230 .cn_arg = &vt_consterm,
234 /* Add to set of consoles. */
235 DATA_SET(cons_set, vt_consterm_consdev);
238 * Right after kmem is done to allow early drivers to use locking and allocate
241 SYSINIT(vt_update_static, SI_SUB_KMEM, SI_ORDER_ANY, vt_update_static,
243 /* Delay until all devices attached, to not waste time. */
244 SYSINIT(vt_early_cons, SI_SUB_INT_CONFIG_HOOKS, SI_ORDER_ANY, vt_upgrade,
247 /* Initialize locks/mem depended members. */
249 vt_update_static(void *dummy)
252 if (!vty_enabled(VTY_VT))
254 if (main_vd->vd_driver != NULL)
255 printf("VT(%s): %s %ux%u\n", main_vd->vd_driver->vd_name,
256 (main_vd->vd_flags & VDF_TEXTMODE) ? "text" : "resolution",
257 main_vd->vd_width, main_vd->vd_height);
259 printf("VT: init without driver.\n");
261 mtx_init(&main_vd->vd_lock, "vtdev", NULL, MTX_DEF);
262 cv_init(&main_vd->vd_winswitch, "vtwswt");
266 vt_schedule_flush(struct vt_device *vd, int ms)
270 /* Default to initial value. */
271 ms = 1000 / VT_TIMERFREQ;
273 callout_schedule(&vd->vd_timer, hz / (1000 / ms));
277 vt_resume_flush_timer(struct vt_device *vd, int ms)
280 if (!(vd->vd_flags & VDF_ASYNC) ||
281 !atomic_cmpset_int(&vd->vd_timer_armed, 0, 1))
284 vt_schedule_flush(vd, ms);
288 vt_suspend_flush_timer(struct vt_device *vd)
291 * As long as this function is called locked, callout_stop()
292 * has the same effect like callout_drain() with regard to
293 * preventing the callback function from executing.
295 VT_LOCK_ASSERT(vd, MA_OWNED);
297 if (!(vd->vd_flags & VDF_ASYNC) ||
298 !atomic_cmpset_int(&vd->vd_timer_armed, 1, 0))
301 callout_stop(&vd->vd_timer);
305 vt_switch_timer(void *arg)
308 vt_late_window_switch((struct vt_window *)arg);
312 vt_save_kbd_mode(struct vt_window *vw, keyboard_t *kbd)
317 ret = kbdd_ioctl(kbd, KDGKBMODE, (caddr_t)&mode);
323 vw->vw_kbdmode = mode;
329 vt_update_kbd_mode(struct vt_window *vw, keyboard_t *kbd)
333 ret = kbdd_ioctl(kbd, KDSKBMODE, (caddr_t)&vw->vw_kbdmode);
341 vt_save_kbd_state(struct vt_window *vw, keyboard_t *kbd)
346 ret = kbdd_ioctl(kbd, KDGKBSTATE, (caddr_t)&state);
352 vw->vw_kbdstate &= ~LOCK_MASK;
353 vw->vw_kbdstate |= state & LOCK_MASK;
359 vt_update_kbd_state(struct vt_window *vw, keyboard_t *kbd)
363 state = vw->vw_kbdstate & LOCK_MASK;
364 ret = kbdd_ioctl(kbd, KDSKBSTATE, (caddr_t)&state);
372 vt_save_kbd_leds(struct vt_window *vw, keyboard_t *kbd)
377 ret = kbdd_ioctl(kbd, KDGETLED, (caddr_t)&leds);
383 vw->vw_kbdstate &= ~LED_MASK;
384 vw->vw_kbdstate |= leds & LED_MASK;
390 vt_update_kbd_leds(struct vt_window *vw, keyboard_t *kbd)
394 leds = vw->vw_kbdstate & LED_MASK;
395 ret = kbdd_ioctl(kbd, KDSETLED, (caddr_t)&leds);
403 vt_window_preswitch(struct vt_window *vw, struct vt_window *curvw)
406 DPRINTF(40, "%s\n", __func__);
407 curvw->vw_switch_to = vw;
408 /* Set timer to allow switch in case when process hang. */
409 callout_reset(&vw->vw_proc_dead_timer, hz * vt_deadtimer,
410 vt_switch_timer, (void *)vw);
411 /* Notify process about vt switch attempt. */
412 DPRINTF(30, "%s: Notify process.\n", __func__);
413 signal_vt_rel(curvw);
419 vt_window_postswitch(struct vt_window *vw)
426 /* vt_late_window_switch will done VT switching for regular case. */
428 vt_late_window_switch(struct vt_window *vw)
432 callout_stop(&vw->vw_proc_dead_timer);
434 ret = vt_window_switch(vw);
438 /* Notify owner process about terminal availability. */
439 if (vw->vw_smode.mode == VT_PROCESS) {
440 ret = vt_window_postswitch(vw);
447 vt_proc_window_switch(struct vt_window *vw)
449 struct vt_window *curvw;
450 struct vt_device *vd;
453 /* Prevent switching to NULL */
455 DPRINTF(30, "%s: Cannot switch: vw is NULL.", __func__);
459 curvw = vd->vd_curwindow;
461 /* Check if virtual terminal is locked */
462 if (curvw->vw_flags & VWF_VTYLOCK)
465 /* Check if switch already in progress */
466 if (curvw->vw_flags & VWF_SWWAIT_REL) {
467 /* Check if switching to same window */
468 if (curvw->vw_switch_to == vw) {
469 DPRINTF(30, "%s: Switch in progress to same vw.", __func__);
470 return (0); /* success */
472 DPRINTF(30, "%s: Switch in progress to different vw.", __func__);
476 /* Avoid switching to already selected window */
478 DPRINTF(30, "%s: Cannot switch: vw == curvw.", __func__);
479 return (0); /* success */
482 /* Ask current process permission to switch away. */
483 if (curvw->vw_smode.mode == VT_PROCESS) {
484 DPRINTF(30, "%s: VT_PROCESS ", __func__);
485 if (vt_proc_alive(curvw) == FALSE) {
486 DPRINTF(30, "Dead. Cleaning.");
489 DPRINTF(30, "%s: Signaling process.\n", __func__);
490 /* Alive, try to ask him. */
491 ret = vt_window_preswitch(vw, curvw);
492 /* Wait for process answer or timeout. */
498 ret = vt_late_window_switch(vw);
502 /* Switch window ignoring process locking. */
504 vt_window_switch(struct vt_window *vw)
506 struct vt_device *vd = vw->vw_device;
507 struct vt_window *curvw = vd->vd_curwindow;
516 if (!(vw->vw_flags & (VWF_OPENED|VWF_CONSOLE))) {
521 vt_suspend_flush_timer(vd);
523 vd->vd_curwindow = vw;
524 vd->vd_flags |= VDF_INVALID;
525 cv_broadcast(&vd->vd_winswitch);
528 if (vd->vd_driver->vd_postswitch)
529 vd->vd_driver->vd_postswitch(vd);
531 vt_resume_flush_timer(vd, 0);
533 /* Restore per-window keyboard mode. */
535 kbd = kbd_get_keyboard(vd->vd_keyboard);
537 if (curvw->vw_kbdmode == K_XLATE)
538 vt_save_kbd_state(curvw, kbd);
540 vt_update_kbd_mode(vw, kbd);
541 vt_update_kbd_state(vw, kbd);
544 DPRINTF(10, "%s(ttyv%d) done\n", __func__, vw->vw_number);
550 vt_termsize(struct vt_device *vd, struct vt_font *vf, term_pos_t *size)
553 size->tp_row = vd->vd_height;
554 size->tp_col = vd->vd_width;
556 size->tp_row /= vf->vf_height;
557 size->tp_col /= vf->vf_width;
562 vt_winsize(struct vt_device *vd, struct vt_font *vf, struct winsize *size)
565 size->ws_row = size->ws_ypixel = vd->vd_height;
566 size->ws_col = size->ws_xpixel = vd->vd_width;
568 size->ws_row /= vf->vf_height;
569 size->ws_col /= vf->vf_width;
574 vt_compute_drawable_area(struct vt_window *vw)
576 struct vt_device *vd;
581 if (vw->vw_font == NULL) {
582 vw->vw_draw_area.tr_begin.tp_col = 0;
583 vw->vw_draw_area.tr_begin.tp_row = 0;
584 vw->vw_draw_area.tr_end.tp_col = vd->vd_width;
585 vw->vw_draw_area.tr_end.tp_row = vd->vd_height;
592 * Compute the drawable area, so that the text is centered on
596 vw->vw_draw_area.tr_begin.tp_col = (vd->vd_width % vf->vf_width) / 2;
597 vw->vw_draw_area.tr_begin.tp_row = (vd->vd_height % vf->vf_height) / 2;
598 vw->vw_draw_area.tr_end.tp_col = vw->vw_draw_area.tr_begin.tp_col +
599 vd->vd_width / vf->vf_width * vf->vf_width;
600 vw->vw_draw_area.tr_end.tp_row = vw->vw_draw_area.tr_begin.tp_row +
601 vd->vd_height / vf->vf_height * vf->vf_height;
605 vt_scroll(struct vt_window *vw, int offset, int whence)
610 if ((vw->vw_flags & VWF_SCROLL) == 0)
613 vt_termsize(vw->vw_device, vw->vw_font, &size);
615 diff = vthistory_seek(&vw->vw_buf, offset, whence);
617 vw->vw_device->vd_flags |= VDF_INVALID;
618 vt_resume_flush_timer(vw->vw_device, 0);
622 vt_machine_kbdevent(int c)
626 case SPCLKEY | DBG: /* kbdmap(5) keyword `debug`. */
628 kdb_enter(KDB_WHY_BREAK, "manual escape to debugger");
630 case SPCLKEY | HALT: /* kbdmap(5) keyword `halt`. */
632 shutdown_nice(RB_HALT);
634 case SPCLKEY | PASTE: /* kbdmap(5) keyword `paste`. */
635 #ifndef SC_NO_CUTPASTE
636 /* Insert text from cut-paste buffer. */
640 case SPCLKEY | PDWN: /* kbdmap(5) keyword `pdwn`. */
642 shutdown_nice(RB_HALT|RB_POWEROFF);
644 case SPCLKEY | PNC: /* kbdmap(5) keyword `panic`. */
646 * Request to immediate panic if sysctl
647 * kern.vt.enable_panic_key allow it.
650 panic("Forced by the panic key");
652 case SPCLKEY | RBT: /* kbdmap(5) keyword `boot`. */
654 shutdown_nice(RB_AUTOBOOT);
656 case SPCLKEY | SPSC: /* kbdmap(5) keyword `spsc`. */
657 /* Force activatation/deactivation of the screen saver. */
660 case SPCLKEY | STBY: /* XXX Not present in kbdcontrol parser. */
661 /* Put machine into Stand-By mode. */
662 power_pm_suspend(POWER_SLEEP_STATE_STANDBY);
664 case SPCLKEY | SUSP: /* kbdmap(5) keyword `susp`. */
665 /* Suspend machine. */
666 power_pm_suspend(POWER_SLEEP_STATE_SUSPEND);
674 vt_scrollmode_kbdevent(struct vt_window *vw, int c, int console)
676 struct vt_device *vd;
680 /* Only special keys handled in ScrollLock mode */
681 if ((c & SPCLKEY) == 0)
687 if (c >= F_SCR && c <= MIN(L_SCR, F_SCR + VT_MAXWINDOWS - 1)) {
688 vw = vd->vd_windows[c - F_SCR];
689 vt_proc_window_switch(vw);
697 /* Turn scrolling off. */
698 vt_scroll(vw, 0, VHS_END);
699 VTBUF_SLCK_DISABLE(&vw->vw_buf);
700 vw->vw_flags &= ~VWF_SCROLL;
703 case FKEY | F(49): /* Home key. */
704 vt_scroll(vw, 0, VHS_SET);
706 case FKEY | F(50): /* Arrow up. */
707 vt_scroll(vw, -1, VHS_CUR);
709 case FKEY | F(51): /* Page up. */
710 vt_termsize(vd, vw->vw_font, &size);
711 vt_scroll(vw, -size.tp_row, VHS_CUR);
713 case FKEY | F(57): /* End key. */
714 vt_scroll(vw, 0, VHS_END);
716 case FKEY | F(58): /* Arrow down. */
717 vt_scroll(vw, 1, VHS_CUR);
719 case FKEY | F(59): /* Page down. */
720 vt_termsize(vd, vw->vw_font, &size);
721 vt_scroll(vw, size.tp_row, VHS_CUR);
730 vt_processkey(keyboard_t *kbd, struct vt_device *vd, int c)
732 struct vt_window *vw = vd->vd_curwindow;
734 #if VT_ALT_TO_ESC_HACK
736 switch (c & ~RELKEY) {
737 case (SPCLKEY | RALT):
738 if (vt_enable_altgr != 0)
740 case (SPCLKEY | LALT):
741 vd->vd_kbstate &= ~ALKED;
743 /* Other keys ignored for RELKEY event. */
746 switch (c & ~RELKEY) {
747 case (SPCLKEY | RALT):
748 if (vt_enable_altgr != 0)
750 case (SPCLKEY | LALT):
751 vd->vd_kbstate |= ALKED;
756 /* Other keys ignored for RELKEY event. */
760 if (vt_machine_kbdevent(c))
763 if (vw->vw_flags & VWF_SCROLL) {
764 vt_scrollmode_kbdevent(vw, c, 0/* Not a console */);
765 /* Scroll mode keys handled, nothing to do more. */
772 if (c >= F_SCR && c <= MIN(L_SCR, F_SCR + VT_MAXWINDOWS - 1)) {
773 vw = vd->vd_windows[c - F_SCR];
774 vt_proc_window_switch(vw);
780 /* Switch to next VT. */
781 c = (vw->vw_number + 1) % VT_MAXWINDOWS;
782 vw = vd->vd_windows[c];
783 vt_proc_window_switch(vw);
786 /* Switch to previous VT. */
787 c = (vw->vw_number + VT_MAXWINDOWS - 1) % VT_MAXWINDOWS;
788 vw = vd->vd_windows[c];
789 vt_proc_window_switch(vw);
792 vt_save_kbd_state(vw, kbd);
794 if (vw->vw_kbdstate & SLKED) {
795 /* Turn scrolling on. */
796 vw->vw_flags |= VWF_SCROLL;
797 VTBUF_SLCK_ENABLE(&vw->vw_buf);
799 /* Turn scrolling off. */
800 vw->vw_flags &= ~VWF_SCROLL;
801 VTBUF_SLCK_DISABLE(&vw->vw_buf);
802 vt_scroll(vw, 0, VHS_END);
807 case FKEY | F(1): case FKEY | F(2): case FKEY | F(3):
808 case FKEY | F(4): case FKEY | F(5): case FKEY | F(6):
809 case FKEY | F(7): case FKEY | F(8): case FKEY | F(9):
810 case FKEY | F(10): case FKEY | F(11): case FKEY | F(12):
811 /* F1 through F12 keys. */
812 terminal_input_special(vw->vw_terminal,
813 TKEY_F1 + c - (FKEY | F(1)));
815 case FKEY | F(49): /* Home key. */
816 terminal_input_special(vw->vw_terminal, TKEY_HOME);
818 case FKEY | F(50): /* Arrow up. */
819 terminal_input_special(vw->vw_terminal, TKEY_UP);
821 case FKEY | F(51): /* Page up. */
822 terminal_input_special(vw->vw_terminal, TKEY_PAGE_UP);
824 case FKEY | F(53): /* Arrow left. */
825 terminal_input_special(vw->vw_terminal, TKEY_LEFT);
827 case FKEY | F(55): /* Arrow right. */
828 terminal_input_special(vw->vw_terminal, TKEY_RIGHT);
830 case FKEY | F(57): /* End key. */
831 terminal_input_special(vw->vw_terminal, TKEY_END);
833 case FKEY | F(58): /* Arrow down. */
834 terminal_input_special(vw->vw_terminal, TKEY_DOWN);
836 case FKEY | F(59): /* Page down. */
837 terminal_input_special(vw->vw_terminal, TKEY_PAGE_DOWN);
839 case FKEY | F(60): /* Insert key. */
840 terminal_input_special(vw->vw_terminal, TKEY_INSERT);
842 case FKEY | F(61): /* Delete key. */
843 terminal_input_special(vw->vw_terminal, TKEY_DELETE);
846 } else if (KEYFLAGS(c) == 0) {
847 /* Don't do UTF-8 conversion when doing raw mode. */
848 if (vw->vw_kbdmode == K_XLATE) {
849 #if VT_ALT_TO_ESC_HACK
850 if (vd->vd_kbstate & ALKED) {
852 * Prepend ESC sequence if one of ALT keys down.
854 terminal_input_char(vw->vw_terminal, 0x1b);
858 kdb_alt_break(c, &vd->vd_altbrk);
860 terminal_input_char(vw->vw_terminal, KEYCHAR(c));
862 terminal_input_raw(vw->vw_terminal, c);
868 vt_kbdevent(keyboard_t *kbd, int event, void *arg)
870 struct vt_device *vd = arg;
876 case KBDIO_UNLOADING:
878 vd->vd_keyboard = -1;
879 kbd_release(kbd, (void *)vd);
886 while ((c = kbdd_read_char(kbd, 0)) != NOKEY)
887 vt_processkey(kbd, vd, c);
893 vt_allocate_keyboard(struct vt_device *vd)
899 idx0 = kbd_allocate("kbdmux", -1, vd, vt_kbdevent, vd);
901 DPRINTF(20, "%s: kbdmux allocated, idx = %d\n", __func__, idx0);
902 k0 = kbd_get_keyboard(idx0);
904 for (idx = kbd_find_keyboard2("*", -1, 0);
906 idx = kbd_find_keyboard2("*", -1, idx + 1)) {
907 k = kbd_get_keyboard(idx);
909 if (idx == idx0 || KBD_IS_BUSY(k))
912 bzero(&ki, sizeof(ki));
913 strncpy(ki.kb_name, k->kb_name, sizeof(ki.kb_name));
914 ki.kb_name[sizeof(ki.kb_name) - 1] = '\0';
915 ki.kb_unit = k->kb_unit;
917 kbdd_ioctl(k0, KBADDKBD, (caddr_t) &ki);
920 DPRINTF(20, "%s: no kbdmux allocated\n", __func__);
921 idx0 = kbd_allocate("*", -1, vd, vt_kbdevent, vd);
923 DPRINTF(10, "%s: No keyboard found.\n", __func__);
927 vd->vd_keyboard = idx0;
928 DPRINTF(20, "%s: vd_keyboard = %d\n", __func__, vd->vd_keyboard);
934 vtterm_bell(struct terminal *tm)
936 struct vt_window *vw = tm->tm_softc;
937 struct vt_device *vd = vw->vw_device;
942 if (vd->vd_flags & VDF_QUIET_BELL)
945 sysbeep(1193182 / VT_BELLPITCH, VT_BELLDURATION);
949 vtterm_beep(struct terminal *tm, u_int param)
956 if ((param == 0) || ((param & 0xffff) == 0)) {
961 period = ((param >> 16) & 0xffff) * hz / 1000;
962 freq = 1193182 / (param & 0xffff);
964 sysbeep(freq, period);
968 vtterm_cursor(struct terminal *tm, const term_pos_t *p)
970 struct vt_window *vw = tm->tm_softc;
972 vtbuf_cursor_position(&vw->vw_buf, p);
973 vt_resume_flush_timer(vw->vw_device, 0);
977 vtterm_putchar(struct terminal *tm, const term_pos_t *p, term_char_t c)
979 struct vt_window *vw = tm->tm_softc;
981 vtbuf_putchar(&vw->vw_buf, p, c);
982 vt_resume_flush_timer(vw->vw_device, 0);
986 vtterm_fill(struct terminal *tm, const term_rect_t *r, term_char_t c)
988 struct vt_window *vw = tm->tm_softc;
990 vtbuf_fill_locked(&vw->vw_buf, r, c);
991 vt_resume_flush_timer(vw->vw_device, 0);
995 vtterm_copy(struct terminal *tm, const term_rect_t *r,
998 struct vt_window *vw = tm->tm_softc;
1000 vtbuf_copy(&vw->vw_buf, r, p);
1001 vt_resume_flush_timer(vw->vw_device, 0);
1005 vtterm_param(struct terminal *tm, int cmd, unsigned int arg)
1007 struct vt_window *vw = tm->tm_softc;
1011 vtbuf_cursor_visibility(&vw->vw_buf, arg);
1012 vt_resume_flush_timer(vw->vw_device, 0);
1015 vw->vw_mouse_level = arg;
1021 vt_determine_colors(term_char_t c, int cursor,
1022 term_color_t *fg, term_color_t *bg)
1029 *fg = TCHAR_FGCOLOR(c);
1030 if (TCHAR_FORMAT(c) & TF_BOLD)
1031 *fg = TCOLOR_LIGHT(*fg);
1032 *bg = TCHAR_BGCOLOR(c);
1034 if (TCHAR_FORMAT(c) & TF_REVERSE)
1046 #ifndef SC_NO_CUTPASTE
1048 vt_is_cursor_in_area(const struct vt_device *vd, const term_rect_t *area)
1050 unsigned int mx, my;
1053 * We use the cursor position saved during the current refresh,
1054 * in case the cursor moved since.
1056 mx = vd->vd_mx_drawn + vd->vd_curwindow->vw_draw_area.tr_begin.tp_col;
1057 my = vd->vd_my_drawn + vd->vd_curwindow->vw_draw_area.tr_begin.tp_row;
1059 if (mx >= area->tr_end.tp_col ||
1060 mx + vd->vd_mcursor->width <= area->tr_begin.tp_col ||
1061 my >= area->tr_end.tp_row ||
1062 my + vd->vd_mcursor->height <= area->tr_begin.tp_row)
1068 vt_mark_mouse_position_as_dirty(struct vt_device *vd)
1071 struct vt_window *vw;
1075 vw = vd->vd_curwindow;
1078 x = vd->vd_mx_drawn;
1079 y = vd->vd_my_drawn;
1082 area.tr_begin.tp_col = x / vf->vf_width;
1083 area.tr_begin.tp_row = y / vf->vf_height;
1084 area.tr_end.tp_col =
1085 ((x + vd->vd_mcursor->width) / vf->vf_width) + 1;
1086 area.tr_end.tp_row =
1087 ((y + vd->vd_mcursor->height) / vf->vf_height) + 1;
1090 * No font loaded (ie. vt_vga operating in textmode).
1092 * FIXME: This fake area needs to be revisited once the
1093 * mouse cursor is supported in vt_vga's textmode.
1095 area.tr_begin.tp_col = x;
1096 area.tr_begin.tp_row = y;
1097 area.tr_end.tp_col = x + 2;
1098 area.tr_end.tp_row = y + 2;
1101 vtbuf_dirty(&vw->vw_buf, &area);
1106 vt_flush(struct vt_device *vd)
1108 struct vt_window *vw;
1112 #ifndef SC_NO_CUTPASTE
1113 int cursor_was_shown, cursor_moved;
1116 vw = vd->vd_curwindow;
1120 if (vd->vd_flags & VDF_SPLASH || vw->vw_flags & VWF_BUSY)
1124 if (((vd->vd_flags & VDF_TEXTMODE) == 0) && (vf == NULL))
1127 #ifndef SC_NO_CUTPASTE
1128 cursor_was_shown = vd->vd_mshown;
1129 cursor_moved = (vd->vd_mx != vd->vd_mx_drawn ||
1130 vd->vd_my != vd->vd_my_drawn);
1132 /* Check if the cursor should be displayed or not. */
1133 if ((vd->vd_flags & VDF_MOUSECURSOR) && /* Mouse support enabled. */
1134 !(vw->vw_flags & VWF_MOUSE_HIDE) && /* Cursor displayed. */
1135 !kdb_active && panicstr == NULL) { /* DDB inactive. */
1142 * If the cursor changed display state or moved, we must mark
1143 * the old position as dirty, so that it's erased.
1145 if (cursor_was_shown != vd->vd_mshown ||
1146 (vd->vd_mshown && cursor_moved))
1147 vt_mark_mouse_position_as_dirty(vd);
1150 * Save position of the mouse cursor. It's used by backends to
1151 * know where to draw the cursor and during the next refresh to
1152 * erase the previous position.
1154 vd->vd_mx_drawn = vd->vd_mx;
1155 vd->vd_my_drawn = vd->vd_my;
1158 * If the cursor is displayed and has moved since last refresh,
1159 * mark the new position as dirty.
1161 if (vd->vd_mshown && cursor_moved)
1162 vt_mark_mouse_position_as_dirty(vd);
1165 vtbuf_undirty(&vw->vw_buf, &tarea);
1166 vt_termsize(vd, vf, &size);
1168 /* Force a full redraw when the screen contents are invalid. */
1169 if (vd->vd_flags & VDF_INVALID) {
1170 tarea.tr_begin.tp_row = tarea.tr_begin.tp_col = 0;
1171 tarea.tr_end = size;
1173 vd->vd_flags &= ~VDF_INVALID;
1176 if (tarea.tr_begin.tp_col < tarea.tr_end.tp_col) {
1177 vd->vd_driver->vd_bitblt_text(vd, vw, &tarea);
1187 struct vt_device *vd;
1191 /* Update screen if required. */
1192 changed = vt_flush(vd);
1194 /* Schedule for next update. */
1196 vt_schedule_flush(vd, 0);
1198 vd->vd_timer_armed = 0;
1202 vtterm_done(struct terminal *tm)
1204 struct vt_window *vw = tm->tm_softc;
1205 struct vt_device *vd = vw->vw_device;
1207 if (kdb_active || panicstr != NULL) {
1208 /* Switch to the debugger. */
1209 if (vd->vd_curwindow != vw) {
1210 vd->vd_curwindow = vw;
1211 vd->vd_flags |= VDF_INVALID;
1212 if (vd->vd_driver->vd_postswitch)
1213 vd->vd_driver->vd_postswitch(vd);
1215 vd->vd_flags &= ~VDF_SPLASH;
1217 } else if (!(vd->vd_flags & VDF_ASYNC)) {
1224 vtterm_splash(struct vt_device *vd)
1226 vt_axis_t top, left;
1228 /* Display a nice boot splash. */
1229 if (!(vd->vd_flags & VDF_TEXTMODE) && (boothowto & RB_MUTE)) {
1231 top = (vd->vd_height - vt_logo_height) / 2;
1232 left = (vd->vd_width - vt_logo_width) / 2;
1233 switch (vt_logo_depth) {
1235 /* XXX: Unhardcode colors! */
1236 vd->vd_driver->vd_bitblt_bmp(vd, vd->vd_curwindow,
1237 vt_logo_image, NULL, vt_logo_width, vt_logo_height,
1238 left, top, TC_WHITE, TC_BLACK);
1240 vd->vd_flags |= VDF_SPLASH;
1247 vtterm_cnprobe(struct terminal *tm, struct consdev *cp)
1249 struct vt_driver *vtd, **vtdlist, *vtdbest = NULL;
1250 struct vt_window *vw = tm->tm_softc;
1251 struct vt_device *vd = vw->vw_device;
1256 if (!vty_enabled(VTY_VT))
1259 if (vd->vd_flags & VDF_INITIALIZED)
1260 /* Initialization already done. */
1263 SET_FOREACH(vtdlist, vt_drv_set) {
1265 if (vtd->vd_probe == NULL)
1267 if (vtd->vd_probe(vd) == CN_DEAD)
1269 if ((vtdbest == NULL) ||
1270 (vtd->vd_priority > vtdbest->vd_priority))
1273 if (vtdbest == NULL) {
1274 cp->cn_pri = CN_DEAD;
1275 vd->vd_flags |= VDF_DEAD;
1277 vd->vd_driver = vtdbest;
1278 cp->cn_pri = vd->vd_driver->vd_init(vd);
1281 /* Check if driver's vt_init return CN_DEAD. */
1282 if (cp->cn_pri == CN_DEAD) {
1283 vd->vd_flags |= VDF_DEAD;
1286 /* Initialize any early-boot keyboard drivers */
1287 kbd_configure(KB_CONF_PROBE_ONLY);
1289 vd->vd_unit = atomic_fetchadd_int(&vt_unit, 1);
1290 vd->vd_windows[VT_CONSWINDOW] = vw;
1291 sprintf(cp->cn_name, "ttyv%r", VT_UNIT(vw));
1293 /* Attach default font if not in TEXTMODE. */
1294 if ((vd->vd_flags & VDF_TEXTMODE) == 0) {
1295 vw->vw_font = vtfont_ref(&vt_font_default);
1296 vt_compute_drawable_area(vw);
1300 * The original screen size was faked (_VTDEFW x _VTDEFH). Now
1301 * that we have the real viewable size, fix it in the static
1304 if (vd->vd_width != 0 && vd->vd_height != 0)
1305 vt_termsize(vd, vw->vw_font, &vw->vw_buf.vb_scr_size);
1307 vtbuf_init_early(&vw->vw_buf);
1308 vt_winsize(vd, vw->vw_font, &wsz);
1309 c = (boothowto & RB_MUTE) == 0 ? TERMINAL_KERN_ATTR :
1311 attr.ta_format = TCHAR_FORMAT(c);
1312 attr.ta_fgcolor = TCHAR_FGCOLOR(c);
1313 attr.ta_bgcolor = TCHAR_BGCOLOR(c);
1314 terminal_set_winsize_blank(tm, &wsz, 1, &attr);
1316 if (vtdbest != NULL) {
1320 vd->vd_flags |= VDF_INITIALIZED;
1325 vtterm_cngetc(struct terminal *tm)
1327 struct vt_window *vw = tm->tm_softc;
1328 struct vt_device *vd = vw->vw_device;
1332 if (vw->vw_kbdsq && *vw->vw_kbdsq)
1333 return (*vw->vw_kbdsq++);
1335 /* Make sure the splash screen is not there. */
1336 if (vd->vd_flags & VDF_SPLASH) {
1338 vd->vd_flags &= ~VDF_SPLASH;
1339 /* Mark screen as invalid to force update */
1340 vd->vd_flags |= VDF_INVALID;
1344 /* Stripped down keyboard handler. */
1345 kbd = kbd_get_keyboard(vd->vd_keyboard);
1349 /* Force keyboard input mode to K_XLATE */
1350 vw->vw_kbdmode = K_XLATE;
1351 vt_update_kbd_mode(vw, kbd);
1353 /* Switch the keyboard to polling to make it work here. */
1354 kbdd_poll(kbd, TRUE);
1355 c = kbdd_read_char(kbd, 0);
1356 kbdd_poll(kbd, FALSE);
1360 if (vw->vw_flags & VWF_SCROLL) {
1361 vt_scrollmode_kbdevent(vw, c, 1/* Console mode */);
1366 /* Stripped down handling of vt_kbdevent(), without locking, etc. */
1370 vt_save_kbd_state(vw, kbd);
1371 if (vw->vw_kbdstate & SLKED) {
1372 /* Turn scrolling on. */
1373 vw->vw_flags |= VWF_SCROLL;
1374 VTBUF_SLCK_ENABLE(&vw->vw_buf);
1376 /* Turn scrolling off. */
1377 vt_scroll(vw, 0, VHS_END);
1378 vw->vw_flags &= ~VWF_SCROLL;
1379 VTBUF_SLCK_DISABLE(&vw->vw_buf);
1382 /* XXX: KDB can handle history. */
1383 case SPCLKEY | FKEY | F(50): /* Arrow up. */
1384 vw->vw_kbdsq = "\x1b[A";
1386 case SPCLKEY | FKEY | F(58): /* Arrow down. */
1387 vw->vw_kbdsq = "\x1b[B";
1389 case SPCLKEY | FKEY | F(55): /* Arrow right. */
1390 vw->vw_kbdsq = "\x1b[C";
1392 case SPCLKEY | FKEY | F(53): /* Arrow left. */
1393 vw->vw_kbdsq = "\x1b[D";
1397 /* Force refresh to make scrollback work. */
1399 } else if (KEYFLAGS(c) == 0) {
1400 return (KEYCHAR(c));
1403 if (vw->vw_kbdsq && *vw->vw_kbdsq)
1404 return (*vw->vw_kbdsq++);
1410 vtterm_cngrab(struct terminal *tm)
1412 struct vt_device *vd;
1413 struct vt_window *vw;
1420 vt_window_switch(vw);
1422 kbd = kbd_get_keyboard(vd->vd_keyboard);
1426 if (vw->vw_grabbed++ > 0)
1430 * Make sure the keyboard is accessible even when the kbd device
1431 * driver is disabled.
1435 /* We shall always use the keyboard in the XLATE mode here. */
1436 vw->vw_prev_kbdmode = vw->vw_kbdmode;
1437 vw->vw_kbdmode = K_XLATE;
1438 vt_update_kbd_mode(vw, kbd);
1440 kbdd_poll(kbd, TRUE);
1444 vtterm_cnungrab(struct terminal *tm)
1446 struct vt_device *vd;
1447 struct vt_window *vw;
1453 kbd = kbd_get_keyboard(vd->vd_keyboard);
1457 if (--vw->vw_grabbed > 0)
1460 kbdd_poll(kbd, FALSE);
1462 vw->vw_kbdmode = vw->vw_prev_kbdmode;
1463 vt_update_kbd_mode(vw, kbd);
1468 vtterm_opened(struct terminal *tm, int opened)
1470 struct vt_window *vw = tm->tm_softc;
1471 struct vt_device *vd = vw->vw_device;
1474 vd->vd_flags &= ~VDF_SPLASH;
1476 vw->vw_flags |= VWF_OPENED;
1478 vw->vw_flags &= ~VWF_OPENED;
1479 /* TODO: finish ACQ/REL */
1485 vt_set_border(struct vt_window *vw, term_color_t c)
1487 struct vt_device *vd = vw->vw_device;
1489 if (vd->vd_driver->vd_drawrect == NULL)
1493 if (vw->vw_draw_area.tr_begin.tp_row > 0)
1494 vd->vd_driver->vd_drawrect(vd,
1496 vd->vd_width - 1, vw->vw_draw_area.tr_begin.tp_row - 1,
1500 if (vw->vw_draw_area.tr_begin.tp_col > 0)
1501 vd->vd_driver->vd_drawrect(vd,
1503 vw->vw_draw_area.tr_begin.tp_col - 1, vd->vd_height - 1,
1507 if (vw->vw_draw_area.tr_end.tp_col < vd->vd_width)
1508 vd->vd_driver->vd_drawrect(vd,
1509 vw->vw_draw_area.tr_end.tp_col - 1, 0,
1510 vd->vd_width - 1, vd->vd_height - 1,
1514 if (vw->vw_draw_area.tr_end.tp_row < vd->vd_height)
1515 vd->vd_driver->vd_drawrect(vd,
1516 0, vw->vw_draw_area.tr_end.tp_row - 1,
1517 vd->vd_width - 1, vd->vd_height - 1,
1524 vt_change_font(struct vt_window *vw, struct vt_font *vf)
1526 struct vt_device *vd = vw->vw_device;
1527 struct terminal *tm = vw->vw_terminal;
1534 * Changing fonts is a little tricky. We must prevent
1535 * simultaneous access to the device, so we must stop
1536 * the display timer and the terminal from accessing.
1537 * We need to switch fonts and grow our screen buffer.
1539 * XXX: Right now the code uses terminal_mute() to
1540 * prevent data from reaching the console driver while
1541 * resizing the screen buffer. This isn't elegant...
1545 if (vw->vw_flags & VWF_BUSY) {
1546 /* Another process is changing the font. */
1550 vw->vw_flags |= VWF_BUSY;
1553 vt_termsize(vd, vf, &size);
1554 vt_winsize(vd, vf, &wsz);
1556 /* Grow the screen buffer and terminal. */
1557 terminal_mute(tm, 1);
1558 vtbuf_grow(&vw->vw_buf, &size, vw->vw_buf.vb_history_size);
1559 terminal_set_winsize_blank(tm, &wsz, 0, NULL);
1560 terminal_set_cursor(tm, &vw->vw_buf.vb_cursor);
1561 terminal_mute(tm, 0);
1563 /* Actually apply the font to the current window. */
1565 if (vw->vw_font != vf && vw->vw_font != NULL && vf != NULL) {
1567 * In case vt_change_font called to update size we don't need
1568 * to update font link.
1570 vtfont_unref(vw->vw_font);
1571 vw->vw_font = vtfont_ref(vf);
1575 * Compute the drawable area and move the mouse cursor inside
1576 * it, in case the new area is smaller than the previous one.
1578 vt_compute_drawable_area(vw);
1579 vd->vd_mx = min(vd->vd_mx,
1580 vw->vw_draw_area.tr_end.tp_col -
1581 vw->vw_draw_area.tr_begin.tp_col - 1);
1582 vd->vd_my = min(vd->vd_my,
1583 vw->vw_draw_area.tr_end.tp_row -
1584 vw->vw_draw_area.tr_begin.tp_row - 1);
1586 /* Force a full redraw the next timer tick. */
1587 if (vd->vd_curwindow == vw) {
1588 vt_set_border(vw, TC_BLACK);
1589 vd->vd_flags |= VDF_INVALID;
1590 vt_resume_flush_timer(vw->vw_device, 0);
1592 vw->vw_flags &= ~VWF_BUSY;
1598 vt_proc_alive(struct vt_window *vw)
1602 if (vw->vw_smode.mode != VT_PROCESS)
1606 if ((p = pfind(vw->vw_pid)) != NULL)
1608 if (vw->vw_proc == p)
1611 vw->vw_smode.mode = VT_AUTO;
1612 DPRINTF(1, "vt controlling process %d died\n", vw->vw_pid);
1619 signal_vt_rel(struct vt_window *vw)
1622 if (vw->vw_smode.mode != VT_PROCESS)
1624 if (vw->vw_proc == NULL || vt_proc_alive(vw) == FALSE) {
1629 vw->vw_flags |= VWF_SWWAIT_REL;
1630 PROC_LOCK(vw->vw_proc);
1631 kern_psignal(vw->vw_proc, vw->vw_smode.relsig);
1632 PROC_UNLOCK(vw->vw_proc);
1633 DPRINTF(1, "sending relsig to %d\n", vw->vw_pid);
1638 signal_vt_acq(struct vt_window *vw)
1641 if (vw->vw_smode.mode != VT_PROCESS)
1643 if (vw == vw->vw_device->vd_windows[VT_CONSWINDOW])
1644 cnavailable(vw->vw_terminal->consdev, FALSE);
1645 if (vw->vw_proc == NULL || vt_proc_alive(vw) == FALSE) {
1650 vw->vw_flags |= VWF_SWWAIT_ACQ;
1651 PROC_LOCK(vw->vw_proc);
1652 kern_psignal(vw->vw_proc, vw->vw_smode.acqsig);
1653 PROC_UNLOCK(vw->vw_proc);
1654 DPRINTF(1, "sending acqsig to %d\n", vw->vw_pid);
1659 finish_vt_rel(struct vt_window *vw, int release, int *s)
1662 if (vw->vw_flags & VWF_SWWAIT_REL) {
1663 vw->vw_flags &= ~VWF_SWWAIT_REL;
1665 callout_drain(&vw->vw_proc_dead_timer);
1666 vt_late_window_switch(vw->vw_switch_to);
1674 finish_vt_acq(struct vt_window *vw)
1677 if (vw->vw_flags & VWF_SWWAIT_ACQ) {
1678 vw->vw_flags &= ~VWF_SWWAIT_ACQ;
1684 #ifndef SC_NO_CUTPASTE
1686 vt_mouse_terminput_button(struct vt_device *vd, int button)
1688 struct vt_window *vw;
1690 char mouseb[6] = "\x1B[M";
1693 vw = vd->vd_curwindow;
1696 /* Translate to char position. */
1697 x = vd->vd_mx / vf->vf_width;
1698 y = vd->vd_my / vf->vf_height;
1699 /* Avoid overflow. */
1700 x = MIN(x, 255 - '!');
1701 y = MIN(y, 255 - '!');
1703 mouseb[3] = ' ' + button;
1704 mouseb[4] = '!' + x;
1705 mouseb[5] = '!' + y;
1707 for (i = 0; i < sizeof(mouseb); i++)
1708 terminal_input_char(vw->vw_terminal, mouseb[i]);
1712 vt_mouse_terminput(struct vt_device *vd, int type, int x, int y, int event,
1717 case MOUSE_BUTTON_EVENT:
1719 /* Mouse button pressed. */
1720 if (event & MOUSE_BUTTON1DOWN)
1721 vt_mouse_terminput_button(vd, 0);
1722 if (event & MOUSE_BUTTON2DOWN)
1723 vt_mouse_terminput_button(vd, 1);
1724 if (event & MOUSE_BUTTON3DOWN)
1725 vt_mouse_terminput_button(vd, 2);
1727 /* Mouse button released. */
1728 vt_mouse_terminput_button(vd, 3);
1732 case MOUSE_MOTION_EVENT:
1733 if (mouse->u.data.z < 0) {
1735 sc_mouse_input_button(vd, 64);
1736 } else if (mouse->u.data.z > 0) {
1738 sc_mouse_input_button(vd, 65);
1751 len = VD_PASTEBUFLEN(main_vd);
1752 buf = VD_PASTEBUF(main_vd);
1753 len /= sizeof(term_char_t);
1754 for (i = 0; i < len; i++) {
1757 terminal_input_char(main_vd->vd_curwindow->vw_terminal,
1763 vt_mouse_event(int type, int x, int y, int event, int cnt, int mlevel)
1765 struct vt_device *vd;
1766 struct vt_window *vw;
1772 vw = vd->vd_curwindow;
1776 if (vw->vw_flags & (VWF_MOUSE_HIDE | VWF_GRAPHICS))
1778 * Either the mouse is disabled, or the window is in
1779 * "graphics mode". The graphics mode is usually set by
1780 * an X server, using the KDSETMODE ioctl.
1784 if (vf == NULL) /* Text mode. */
1788 * TODO: add flag about pointer position changed, to not redraw chars
1789 * under mouse pointer when nothing changed.
1792 if (vw->vw_mouse_level > 0)
1793 vt_mouse_terminput(vd, type, x, y, event, cnt);
1797 case MOUSE_MOTION_EVENT:
1802 vt_termsize(vd, vf, &size);
1807 x = MIN(x, (size.tp_col * vf->vf_width) - 1);
1808 y = MIN(y, (size.tp_row * vf->vf_height) - 1);
1812 if (vd->vd_mstate & MOUSE_BUTTON1DOWN)
1813 vtbuf_set_mark(&vw->vw_buf, VTB_MARK_MOVE,
1814 vd->vd_mx / vf->vf_width,
1815 vd->vd_my / vf->vf_height);
1817 vt_resume_flush_timer(vw->vw_device, 0);
1819 case MOUSE_BUTTON_EVENT:
1827 case MOUSE_BUTTON1DOWN:
1830 mark = VTB_MARK_END;
1832 case 1: /* single click: start cut operation */
1833 mark = VTB_MARK_START;
1835 case 2: /* double click: cut a word */
1836 mark = VTB_MARK_WORD;
1838 case 3: /* triple click: cut a line */
1839 mark = VTB_MARK_ROW;
1843 case VT_MOUSE_PASTEBUTTON:
1852 case VT_MOUSE_EXTENDBUTTON:
1855 if (!(vd->vd_mstate & MOUSE_BUTTON1DOWN))
1856 mark = VTB_MARK_EXTEND;
1861 mark = VTB_MARK_EXTEND;
1869 /* Save buttons state. */
1871 vd->vd_mstate |= event;
1873 vd->vd_mstate &= ~event;
1875 if (vtbuf_set_mark(&vw->vw_buf, mark, vd->vd_mx / vf->vf_width,
1876 vd->vd_my / vf->vf_height) == 1) {
1878 * We have something marked to copy, so update pointer to
1879 * window with selection.
1881 vt_resume_flush_timer(vw->vw_device, 0);
1887 case VTB_MARK_EXTEND:
1890 /* Other types of mark do not require to copy data. */
1894 /* Get current selection size in bytes. */
1895 len = vtbuf_get_marked_len(&vw->vw_buf);
1899 /* Reallocate buffer only if old one is too small. */
1900 if (len > VD_PASTEBUFSZ(vd)) {
1901 VD_PASTEBUF(vd) = realloc(VD_PASTEBUF(vd), len, M_VT,
1903 /* Update buffer size. */
1904 VD_PASTEBUFSZ(vd) = len;
1906 /* Request copy/paste buffer data, no more than `len' */
1907 vtbuf_extract_marked(&vw->vw_buf, VD_PASTEBUF(vd),
1910 VD_PASTEBUFLEN(vd) = len;
1912 /* XXX VD_PASTEBUF(vd) have to be freed on shutdown/unload. */
1917 vt_mouse_state(int show)
1919 struct vt_device *vd;
1920 struct vt_window *vw;
1923 vw = vd->vd_curwindow;
1927 vw->vw_flags |= VWF_MOUSE_HIDE;
1930 vw->vw_flags &= ~VWF_MOUSE_HIDE;
1934 /* Mark mouse position as dirty. */
1935 vt_mark_mouse_position_as_dirty(vd);
1936 vt_resume_flush_timer(vw->vw_device, 0);
1941 vtterm_mmap(struct terminal *tm, vm_ooffset_t offset, vm_paddr_t * paddr,
1942 int nprot, vm_memattr_t *memattr)
1944 struct vt_window *vw = tm->tm_softc;
1945 struct vt_device *vd = vw->vw_device;
1947 if (vd->vd_driver->vd_fb_mmap)
1948 return (vd->vd_driver->vd_fb_mmap(vd, offset, paddr, nprot,
1955 vtterm_ioctl(struct terminal *tm, u_long cmd, caddr_t data,
1958 struct vt_window *vw = tm->tm_softc;
1959 struct vt_device *vd = vw->vw_device;
1962 #if defined(COMPAT_FREEBSD6) || defined(COMPAT_FREEBSD5) || \
1963 defined(COMPAT_FREEBSD4) || defined(COMPAT_43)
1974 cmd = VT_WAITACTIVE;
2000 ival = IOCPARM_IVAL(data);
2001 data = (caddr_t)&ival;
2006 case KDSETRAD: /* set keyboard repeat & delay rates (old) */
2007 if (*(int *)data & ~0x7f)
2012 case GIO_DEADKEYMAP:
2013 case PIO_DEADKEYMAP:
2018 case KDGETREPEAT: /* get keyboard repeat & delay rates */
2019 case KDSETREPEAT: /* set keyboard repeat & delay rates (new) */
2020 case KBADDKBD: /* add/remove keyboard to/from mux */
2025 kbd = kbd_get_keyboard(vd->vd_keyboard);
2027 error = kbdd_ioctl(kbd, cmd, data);
2029 if (error == ENOIOCTL) {
2030 if (cmd == KDGKBTYPE) {
2031 /* always return something? XXX */
2039 case KDGKBSTATE: { /* get keyboard state (locks) */
2042 if (vw == vd->vd_curwindow) {
2044 kbd = kbd_get_keyboard(vd->vd_keyboard);
2046 error = vt_save_kbd_state(vw, kbd);
2053 *(int *)data = vw->vw_kbdstate & LOCK_MASK;
2057 case KDSKBSTATE: { /* set keyboard state (locks) */
2060 state = *(int *)data;
2061 if (state & ~LOCK_MASK)
2064 vw->vw_kbdstate &= ~LOCK_MASK;
2065 vw->vw_kbdstate |= state;
2068 if (vw == vd->vd_curwindow) {
2070 kbd = kbd_get_keyboard(vd->vd_keyboard);
2072 error = vt_update_kbd_state(vw, kbd);
2078 case KDGETLED: { /* get keyboard LED status */
2081 if (vw == vd->vd_curwindow) {
2083 kbd = kbd_get_keyboard(vd->vd_keyboard);
2085 error = vt_save_kbd_leds(vw, kbd);
2092 *(int *)data = vw->vw_kbdstate & LED_MASK;
2096 case KDSETLED: { /* set keyboard LED status */
2099 leds = *(int *)data;
2100 if (leds & ~LED_MASK)
2103 vw->vw_kbdstate &= ~LED_MASK;
2104 vw->vw_kbdstate |= leds;
2107 if (vw == vd->vd_curwindow) {
2109 kbd = kbd_get_keyboard(vd->vd_keyboard);
2111 error = vt_update_kbd_leds(vw, kbd);
2120 if (vw == vd->vd_curwindow) {
2122 kbd = kbd_get_keyboard(vd->vd_keyboard);
2124 error = vt_save_kbd_mode(vw, kbd);
2131 *(int *)data = vw->vw_kbdmode;
2138 mode = *(int *)data;
2143 vw->vw_kbdmode = mode;
2146 if (vw == vd->vd_curwindow) {
2148 kbd = kbd_get_keyboard(vd->vd_keyboard);
2150 error = vt_update_kbd_mode(vw, kbd);
2160 case FBIO_GETWINORG: /* get frame buffer window origin */
2161 case FBIO_GETDISPSTART: /* get display start address */
2162 case FBIO_GETLINEWIDTH: /* get scan line width in bytes */
2163 case FBIO_BLANK: /* blank display */
2164 if (vd->vd_driver->vd_fb_ioctl)
2165 return (vd->vd_driver->vd_fb_ioctl(vd, cmd, data, td));
2167 case CONS_BLANKTIME:
2172 *(int *)data = M_CG640x480;
2174 case CONS_BELLTYPE: /* set bell type sound */
2175 if ((*(int *)data) & CONS_QUIET_BELL)
2176 vd->vd_flags |= VDF_QUIET_BELL;
2178 vd->vd_flags &= ~VDF_QUIET_BELL;
2180 case CONS_GETINFO: {
2181 vid_info_t *vi = (vid_info_t *)data;
2182 if (vi->size != sizeof(struct vid_info))
2185 if (vw == vd->vd_curwindow) {
2186 kbd = kbd_get_keyboard(vd->vd_keyboard);
2188 vt_save_kbd_state(vw, kbd);
2191 vi->m_num = vd->vd_curwindow->vw_number + 1;
2192 vi->mk_keylock = vw->vw_kbdstate & LOCK_MASK;
2193 /* XXX: other fields! */
2197 *(int *)data = 0x200;
2202 case CONS_MOUSECTL: {
2203 mouse_info_t *mouse = (mouse_info_t*)data;
2206 * All the commands except MOUSE_SHOW nd MOUSE_HIDE
2207 * should not be applied to individual TTYs, but only to
2210 switch (mouse->operation) {
2212 if (vd->vd_flags & VDF_MOUSECURSOR) {
2213 vd->vd_flags &= ~VDF_MOUSECURSOR;
2214 #ifndef SC_NO_CUTPASTE
2215 vt_mouse_state(VT_MOUSE_HIDE);
2220 if (!(vd->vd_flags & VDF_MOUSECURSOR)) {
2221 vd->vd_flags |= VDF_MOUSECURSOR;
2222 vd->vd_mx = vd->vd_width / 2;
2223 vd->vd_my = vd->vd_height / 2;
2224 #ifndef SC_NO_CUTPASTE
2225 vt_mouse_state(VT_MOUSE_SHOW);
2236 if (vd->vd_flags & VDF_TEXTMODE)
2239 error = vtfont_load((void *)data, &vf);
2243 error = vt_change_font(vw, vf);
2247 case PIO_VFONT_DEFAULT: {
2248 /* Reset to default font. */
2249 error = vt_change_font(vw, &vt_font_default);
2253 scrmap_t *sm = (scrmap_t *)data;
2255 /* We don't have screen maps, so return a handcrafted one. */
2256 for (i = 0; i < 256; i++)
2262 * FIXME: This implementation is incomplete compared to
2265 switch (*(int *)data) {
2269 vw->vw_flags &= ~VWF_GRAPHICS;
2272 vw->vw_flags |= VWF_GRAPHICS;
2276 case KDENABIO: /* allow io operations */
2277 error = priv_check(td, PRIV_IO);
2280 error = securelevel_gt(td->td_ucred, 0);
2283 #if defined(__i386__)
2284 td->td_frame->tf_eflags |= PSL_IOPL;
2285 #elif defined(__amd64__)
2286 td->td_frame->tf_rflags |= PSL_IOPL;
2289 case KDDISABIO: /* disallow io operations (default) */
2290 #if defined(__i386__)
2291 td->td_frame->tf_eflags &= ~PSL_IOPL;
2292 #elif defined(__amd64__)
2293 td->td_frame->tf_rflags &= ~PSL_IOPL;
2296 case KDMKTONE: /* sound the bell */
2297 vtterm_beep(tm, *(u_int *)data);
2299 case KIOCSOUND: /* make tone (*data) hz */
2302 case CONS_SETKBD: /* set the new keyboard */
2305 if (vd->vd_keyboard != *(int *)data) {
2306 kbd = kbd_get_keyboard(*(int *)data);
2311 i = kbd_allocate(kbd->kb_name, kbd->kb_unit,
2312 (void *)vd, vt_kbdevent, vd);
2314 if (vd->vd_keyboard != -1) {
2315 vt_save_kbd_state(vd->vd_curwindow, kbd);
2316 kbd_release(kbd, (void *)vd);
2318 kbd = kbd_get_keyboard(i);
2319 vd->vd_keyboard = i;
2321 vt_update_kbd_mode(vd->vd_curwindow, kbd);
2322 vt_update_kbd_state(vd->vd_curwindow, kbd);
2324 error = EPERM; /* XXX */
2329 case CONS_RELKBD: /* release the current keyboard */
2332 if (vd->vd_keyboard != -1) {
2333 kbd = kbd_get_keyboard(vd->vd_keyboard);
2338 vt_save_kbd_state(vd->vd_curwindow, kbd);
2339 error = kbd_release(kbd, (void *)vd);
2341 vd->vd_keyboard = -1;
2348 win = *(int *)data - 1;
2349 DPRINTF(5, "%s%d: VT_ACTIVATE ttyv%d ", SC_DRIVER_NAME,
2351 if ((win >= VT_MAXWINDOWS) || (win < 0))
2353 return (vt_proc_window_switch(vd->vd_windows[win]));
2356 *(int *)data = vd->vd_curwindow->vw_number + 1;
2359 *(int *)data = vw->vw_number + 1;
2362 /* TODO: Check current state, switching can be in progress. */
2363 if ((*(int *)data) == 0x01)
2364 vw->vw_flags |= VWF_VTYLOCK;
2365 else if ((*(int *)data) == 0x02)
2366 vw->vw_flags &= ~VWF_VTYLOCK;
2372 for (i = 0; i < VT_MAXWINDOWS; i++) {
2373 vw = vd->vd_windows[i];
2376 if (!(vw->vw_flags & VWF_OPENED)) {
2377 *(int *)data = vw->vw_number + 1;
2384 case VT_WAITACTIVE: {
2389 idx = *(unsigned int *)data;
2390 if (idx > VT_MAXWINDOWS)
2393 vw = vd->vd_windows[idx - 1];
2396 while (vd->vd_curwindow != vw && error == 0)
2397 error = cv_wait_sig(&vd->vd_winswitch, &vd->vd_lock);
2401 case VT_SETMODE: { /* set screen switcher mode */
2402 struct vt_mode *mode;
2405 mode = (struct vt_mode *)data;
2406 DPRINTF(5, "%s%d: VT_SETMODE ", SC_DRIVER_NAME, VT_UNIT(vw));
2407 if (vw->vw_smode.mode == VT_PROCESS) {
2408 p1 = pfind(vw->vw_pid);
2409 if (vw->vw_proc == p1 && vw->vw_proc != td->td_proc) {
2412 DPRINTF(5, "error EPERM\n");
2418 if (mode->mode == VT_AUTO) {
2419 vw->vw_smode.mode = VT_AUTO;
2422 DPRINTF(5, "VT_AUTO, ");
2423 if (vw == vw->vw_device->vd_windows[VT_CONSWINDOW])
2424 cnavailable(vw->vw_terminal->consdev, TRUE);
2425 /* were we in the middle of the vty switching process? */
2426 if (finish_vt_rel(vw, TRUE, &s) == 0)
2427 DPRINTF(5, "reset WAIT_REL, ");
2428 if (finish_vt_acq(vw) == 0)
2429 DPRINTF(5, "reset WAIT_ACQ, ");
2431 } else if (mode->mode == VT_PROCESS) {
2432 if (!ISSIGVALID(mode->relsig) ||
2433 !ISSIGVALID(mode->acqsig) ||
2434 !ISSIGVALID(mode->frsig)) {
2435 DPRINTF(5, "error EINVAL\n");
2438 DPRINTF(5, "VT_PROCESS %d, ", td->td_proc->p_pid);
2439 bcopy(data, &vw->vw_smode, sizeof(struct vt_mode));
2440 vw->vw_proc = td->td_proc;
2441 vw->vw_pid = vw->vw_proc->p_pid;
2442 if (vw == vw->vw_device->vd_windows[VT_CONSWINDOW])
2443 cnavailable(vw->vw_terminal->consdev, FALSE);
2445 DPRINTF(5, "VT_SETMODE failed, unknown mode %d\n",
2452 case VT_GETMODE: /* get screen switcher mode */
2453 bcopy(&vw->vw_smode, data, sizeof(struct vt_mode));
2456 case VT_RELDISP: /* screen switcher ioctl */
2458 * This must be the current vty which is in the VT_PROCESS
2461 if ((vw != vd->vd_curwindow) || (vw->vw_smode.mode !=
2465 /* ...and this process is controlling it. */
2466 if (vw->vw_proc != td->td_proc) {
2470 switch(*(int *)data) {
2471 case VT_FALSE: /* user refuses to release screen, abort */
2472 if ((error = finish_vt_rel(vw, FALSE, &s)) == 0)
2473 DPRINTF(5, "%s%d: VT_RELDISP: VT_FALSE\n",
2474 SC_DRIVER_NAME, VT_UNIT(vw));
2476 case VT_TRUE: /* user has released screen, go on */
2477 /* finish_vt_rel(..., TRUE, ...) should not be locked */
2478 if (vw->vw_flags & VWF_SWWAIT_REL) {
2479 if ((error = finish_vt_rel(vw, TRUE, &s)) == 0)
2480 DPRINTF(5, "%s%d: VT_RELDISP: VT_TRUE\n",
2481 SC_DRIVER_NAME, VT_UNIT(vw));
2486 case VT_ACKACQ: /* acquire acknowledged, switch completed */
2487 if ((error = finish_vt_acq(vw)) == 0)
2488 DPRINTF(5, "%s%d: VT_RELDISP: VT_ACKACQ\n",
2489 SC_DRIVER_NAME, VT_UNIT(vw));
2500 static struct vt_window *
2501 vt_allocate_window(struct vt_device *vd, unsigned int window)
2503 struct vt_window *vw;
2504 struct terminal *tm;
2508 vw = malloc(sizeof *vw, M_VT, M_WAITOK|M_ZERO);
2510 vw->vw_number = window;
2511 vw->vw_kbdmode = K_XLATE;
2513 if ((vd->vd_flags & VDF_TEXTMODE) == 0) {
2514 vw->vw_font = vtfont_ref(&vt_font_default);
2515 vt_compute_drawable_area(vw);
2518 vt_termsize(vd, vw->vw_font, &size);
2519 vt_winsize(vd, vw->vw_font, &wsz);
2520 vtbuf_init(&vw->vw_buf, &size);
2522 tm = vw->vw_terminal = terminal_alloc(&vt_termclass, vw);
2523 terminal_set_winsize(tm, &wsz);
2524 vd->vd_windows[window] = vw;
2525 callout_init(&vw->vw_proc_dead_timer, 0);
2531 vt_upgrade(struct vt_device *vd)
2533 struct vt_window *vw;
2535 int register_handlers;
2537 if (!vty_enabled(VTY_VT))
2539 if (main_vd->vd_driver == NULL)
2542 for (i = 0; i < VT_MAXWINDOWS; i++) {
2543 vw = vd->vd_windows[i];
2546 vw = vt_allocate_window(vd, i);
2548 if (!(vw->vw_flags & VWF_READY)) {
2549 callout_init(&vw->vw_proc_dead_timer, 0);
2550 terminal_maketty(vw->vw_terminal, "v%r", VT_UNIT(vw));
2551 vw->vw_flags |= VWF_READY;
2552 if (vw->vw_flags & VWF_CONSOLE) {
2553 /* For existing console window. */
2554 EVENTHANDLER_REGISTER(shutdown_pre_sync,
2555 vt_window_switch, vw, SHUTDOWN_PRI_DEFAULT);
2561 if (vd->vd_curwindow == NULL)
2562 vd->vd_curwindow = vd->vd_windows[VT_CONSWINDOW];
2564 register_handlers = 0;
2565 if (!(vd->vd_flags & VDF_ASYNC)) {
2566 /* Attach keyboard. */
2567 vt_allocate_keyboard(vd);
2569 /* Init 25 Hz timer. */
2570 callout_init_mtx(&vd->vd_timer, &vd->vd_lock, 0);
2572 /* Start timer when everything ready. */
2573 vd->vd_flags |= VDF_ASYNC;
2574 callout_reset(&vd->vd_timer, hz / VT_TIMERFREQ, vt_timer, vd);
2575 vd->vd_timer_armed = 1;
2576 register_handlers = 1;
2581 /* Refill settings with new sizes. */
2584 if (register_handlers) {
2585 /* Register suspend/resume handlers. */
2586 EVENTHANDLER_REGISTER(power_suspend_early, vt_suspend_handler,
2587 vd, EVENTHANDLER_PRI_ANY);
2588 EVENTHANDLER_REGISTER(power_resume, vt_resume_handler, vd,
2589 EVENTHANDLER_PRI_ANY);
2594 vt_resize(struct vt_device *vd)
2596 struct vt_window *vw;
2599 for (i = 0; i < VT_MAXWINDOWS; i++) {
2600 vw = vd->vd_windows[i];
2602 /* Assign default font to window, if not textmode. */
2603 if (!(vd->vd_flags & VDF_TEXTMODE) && vw->vw_font == NULL)
2604 vw->vw_font = vtfont_ref(&vt_font_default);
2607 /* Resize terminal windows */
2608 while (vt_change_font(vw, vw->vw_font) == EBUSY) {
2609 DPRINTF(100, "%s: vt_change_font() is busy, "
2610 "window %d\n", __func__, i);
2616 vt_allocate(struct vt_driver *drv, void *softc)
2618 struct vt_device *vd;
2620 if (!vty_enabled(VTY_VT))
2623 if (main_vd->vd_driver == NULL) {
2624 main_vd->vd_driver = drv;
2625 printf("VT: initialize with new VT driver \"%s\".\n",
2629 * Check if have rights to replace current driver. For example:
2630 * it is bad idea to replace KMS driver with generic VGA one.
2632 if (drv->vd_priority <= main_vd->vd_driver->vd_priority) {
2633 printf("VT: Driver priority %d too low. Current %d\n ",
2634 drv->vd_priority, main_vd->vd_driver->vd_priority);
2637 printf("VT: Replacing driver \"%s\" with new \"%s\".\n",
2638 main_vd->vd_driver->vd_name, drv->vd_name);
2642 if (vd->vd_flags & VDF_ASYNC) {
2643 /* Stop vt_flush periodic task. */
2645 vt_suspend_flush_timer(vd);
2648 * Mute current terminal until we done. vt_change_font (called
2649 * from vt_resize) will unmute it.
2651 terminal_mute(vd->vd_curwindow->vw_terminal, 1);
2655 * Reset VDF_TEXTMODE flag, driver who require that flag (vt_vga) will
2659 vd->vd_flags &= ~VDF_TEXTMODE;
2661 vd->vd_driver = drv;
2662 vd->vd_softc = softc;
2663 vd->vd_driver->vd_init(vd);
2666 /* Update windows sizes and initialize last items. */
2670 if (vd->vd_flags & VDF_SPLASH)
2674 if (vd->vd_flags & VDF_ASYNC) {
2675 /* Allow to put chars now. */
2676 terminal_mute(vd->vd_curwindow->vw_terminal, 0);
2677 /* Rerun timer for screen updates. */
2678 vt_resume_flush_timer(vd, 0);
2682 * Register as console. If it already registered, cnadd() will ignore
2685 termcn_cnregister(vd->vd_windows[VT_CONSWINDOW]->vw_terminal);
2689 vt_suspend_handler(void *priv)
2691 struct vt_device *vd;
2694 if (vd->vd_driver != NULL && vd->vd_driver->vd_suspend != NULL)
2695 vd->vd_driver->vd_suspend(vd);
2699 vt_resume_handler(void *priv)
2701 struct vt_device *vd;
2704 if (vd->vd_driver != NULL && vd->vd_driver->vd_resume != NULL)
2705 vd->vd_driver->vd_resume(vd);
2709 vt_suspend(struct vt_device *vd)
2713 if (vt_suspendswitch == 0)
2715 /* Save current window. */
2716 vd->vd_savedwindow = vd->vd_curwindow;
2717 /* Ask holding process to free window and switch to console window */
2718 vt_proc_window_switch(vd->vd_windows[VT_CONSWINDOW]);
2720 /* Wait for the window switch to complete. */
2723 while (vd->vd_curwindow != vd->vd_windows[VT_CONSWINDOW] && error == 0)
2724 error = cv_wait_sig(&vd->vd_winswitch, &vd->vd_lock);
2729 vt_resume(struct vt_device *vd)
2732 if (vt_suspendswitch == 0)
2734 /* Switch back to saved window, if any */
2735 vt_proc_window_switch(vd->vd_savedwindow);
2736 vd->vd_savedwindow = NULL;