2 * Copyright (c) 1992-1998 Søren Schmidt
5 * This code is derived from software contributed to The DragonFly Project
6 * by Sascha Wildner <saw@online.de>
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
11 * 1. Redistributions of source code must retain the above copyright
12 * notice, this list of conditions and the following disclaimer,
13 * without modification, immediately at the beginning of the file.
14 * 2. Redistributions in binary form must reproduce the above copyright
15 * notice, this list of conditions and the following disclaimer in the
16 * documentation and/or other materials provided with the distribution.
17 * 3. The name of the author may not be used to endorse or promote products
18 * derived from this software without specific prior written permission.
20 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
21 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
22 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
23 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
24 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
25 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
26 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
27 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
28 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
29 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32 #include <sys/cdefs.h>
33 __FBSDID("$FreeBSD$");
35 #include "opt_compat.h"
36 #include "opt_syscons.h"
37 #include "opt_splash.h"
40 #include <sys/param.h>
41 #include <sys/systm.h>
44 #include <sys/consio.h>
46 #include <sys/eventhandler.h>
49 #include <sys/kernel.h>
51 #include <sys/malloc.h>
52 #include <sys/mutex.h>
55 #include <sys/random.h>
56 #include <sys/reboot.h>
57 #include <sys/signalvar.h>
58 #include <sys/sysctl.h>
60 #include <sys/power.h>
62 #include <machine/clock.h>
63 #if defined(__sparc64__) || defined(__powerpc__)
64 #include <machine/sc_machdep.h>
66 #include <machine/pc/display.h>
68 #if defined( __i386__) || defined(__amd64__)
69 #include <machine/psl.h>
70 #include <machine/frame.h>
73 #include <dev/kbd/kbdreg.h>
74 #include <dev/fb/fbreg.h>
75 #include <dev/fb/splashreg.h>
76 #include <dev/syscons/syscons.h>
81 #define DEFAULT_BLANKTIME (5*60) /* 5 minutes */
82 #define MAX_BLANKTIME (7*24*60*60) /* 7 days!? */
84 #define KEYCODE_BS 0x0e /* "<-- Backspace" key, XXX */
86 typedef struct default_attr {
87 int std_color; /* normal hardware color */
88 int rev_color; /* reverse hardware color */
91 static default_attr user_default = {
96 static default_attr kernel_default = {
98 SC_KERNEL_CONS_REV_ATTR,
101 static int sc_console_unit = -1;
102 static int sc_saver_keyb_only = 1;
103 static scr_stat *sc_console;
104 static struct tty *sc_console_tty;
105 static struct consdev *sc_consptr;
106 static void *kernel_console_ts;
107 static scr_stat main_console;
108 static struct cdev *main_devs[MAXCONS];
110 static char init_done = COLD;
111 static char shutdown_in_progress = FALSE;
112 static char sc_malloc = FALSE;
114 static int saver_mode = CONS_NO_SAVER; /* LKM/user saver */
115 static int run_scrn_saver = FALSE; /* should run the saver? */
116 static int enable_bell = TRUE; /* enable beeper */
118 #ifndef SC_DISABLE_REBOOT
119 static int enable_reboot = TRUE; /* enable keyboard reboot */
122 #ifndef SC_DISABLE_KDBKEY
123 static int enable_kdbkey = TRUE; /* enable keyboard debug */
126 static long scrn_blank_time = 0; /* screen saver timeout value */
128 static int scrn_blanked; /* # of blanked screen */
129 static int sticky_splash = FALSE;
131 static void none_saver(sc_softc_t *sc, int blank) { }
132 static void (*current_saver)(sc_softc_t *, int) = none_saver;
135 SYSCTL_NODE(_hw, OID_AUTO, syscons, CTLFLAG_RD, 0, "syscons");
136 SYSCTL_NODE(_hw_syscons, OID_AUTO, saver, CTLFLAG_RD, 0, "saver");
137 SYSCTL_INT(_hw_syscons_saver, OID_AUTO, keybonly, CTLFLAG_RW,
138 &sc_saver_keyb_only, 0, "screen saver interrupted by input only");
139 SYSCTL_INT(_hw_syscons, OID_AUTO, bell, CTLFLAG_RW, &enable_bell,
141 #ifndef SC_DISABLE_REBOOT
142 SYSCTL_INT(_hw_syscons, OID_AUTO, kbd_reboot, CTLFLAG_RW|CTLFLAG_SECURE, &enable_reboot,
143 0, "enable keyboard reboot");
145 #ifndef SC_DISABLE_KDBKEY
146 SYSCTL_INT(_hw_syscons, OID_AUTO, kbd_debug, CTLFLAG_RW|CTLFLAG_SECURE, &enable_kdbkey,
147 0, "enable keyboard debug");
149 #if !defined(SC_NO_FONT_LOADING) && defined(SC_DFLT_FONT)
153 d_ioctl_t *sc_user_ioctl;
155 static bios_values_t bios_value;
157 static int enable_panic_key;
158 SYSCTL_INT(_machdep, OID_AUTO, enable_panic_key, CTLFLAG_RW, &enable_panic_key,
159 0, "Enable panic via keypress specified in kbdmap(5)");
161 #define SC_CONSOLECTL 255
163 #define VIRTUAL_TTY(sc, x) (SC_DEV((sc), (x)) != NULL ? \
164 SC_DEV((sc), (x))->si_tty : NULL)
165 #define ISTTYOPEN(tp) ((tp) && ((tp)->t_state & TS_ISOPEN))
170 static int sc_allocate_keyboard(sc_softc_t *sc, int unit);
171 static struct tty *sc_alloc_tty(struct cdev *dev);
172 static int scvidprobe(int unit, int flags, int cons);
173 static int sckbdprobe(int unit, int flags, int cons);
174 static void scmeminit(void *arg);
175 static int scdevtounit(struct cdev *dev);
176 static kbd_callback_func_t sckbdevent;
177 static int scparam(struct tty *tp, struct termios *t);
178 static void scstart(struct tty *tp);
179 static void scinit(int unit, int flags);
180 static scr_stat *sc_get_stat(struct cdev *devptr);
181 static void scterm(int unit, int flags);
182 static void scshutdown(void *arg, int howto);
183 static u_int scgetc(sc_softc_t *sc, u_int flags);
185 #define SCGETC_NONBLOCK 2
186 static int sccngetch(int flags);
187 static void sccnupdate(scr_stat *scp);
188 static scr_stat *alloc_scp(sc_softc_t *sc, int vty);
189 static void init_scp(sc_softc_t *sc, int vty, scr_stat *scp);
190 static timeout_t scrn_timer;
191 static int and_region(int *s1, int *e1, int s2, int e2);
192 static void scrn_update(scr_stat *scp, int show_cursor);
195 static int scsplash_callback(int event, void *arg);
196 static void scsplash_saver(sc_softc_t *sc, int show);
197 static int add_scrn_saver(void (*this_saver)(sc_softc_t *, int));
198 static int remove_scrn_saver(void (*this_saver)(sc_softc_t *, int));
199 static int set_scrn_saver_mode(scr_stat *scp, int mode, u_char *pal, int border);
200 static int restore_scrn_saver_mode(scr_stat *scp, int changemode);
201 static void stop_scrn_saver(sc_softc_t *sc, void (*saver)(sc_softc_t *, int));
202 static int wait_scrn_saver_stop(sc_softc_t *sc);
203 #define scsplash_stick(stick) (sticky_splash = (stick))
204 #else /* !DEV_SPLASH */
205 #define scsplash_stick(stick)
206 #endif /* DEV_SPLASH */
208 static int do_switch_scr(sc_softc_t *sc, int s);
209 static int vt_proc_alive(scr_stat *scp);
210 static int signal_vt_rel(scr_stat *scp);
211 static int signal_vt_acq(scr_stat *scp);
212 static int finish_vt_rel(scr_stat *scp, int release, int *s);
213 static int finish_vt_acq(scr_stat *scp);
214 static void exchange_scr(sc_softc_t *sc);
215 static void update_cursor_image(scr_stat *scp);
216 static void change_cursor_shape(scr_stat *scp, int flags, int base, int height);
217 static int save_kbd_state(scr_stat *scp);
218 static int update_kbd_state(scr_stat *scp, int state, int mask);
219 static int update_kbd_leds(scr_stat *scp, int which);
220 static timeout_t blink_screen;
222 static cn_probe_t sc_cnprobe;
223 static cn_init_t sc_cninit;
224 static cn_term_t sc_cnterm;
225 static cn_getc_t sc_cngetc;
226 static cn_putc_t sc_cnputc;
230 static d_open_t scopen;
231 static d_close_t scclose;
232 static d_read_t scread;
233 static d_ioctl_t scioctl;
234 static d_mmap_t scmmap;
236 static struct cdevsw sc_cdevsw = {
237 .d_version = D_VERSION,
244 .d_flags = D_TTY | D_NEEDGIANT,
248 sc_probe_unit(int unit, int flags)
250 if (!scvidprobe(unit, flags, FALSE)) {
252 printf("%s%d: no video adapter found.\n", SC_DRIVER_NAME, unit);
256 /* syscons will be attached even when there is no keyboard */
257 sckbdprobe(unit, flags, FALSE);
262 /* probe video adapters, return TRUE if found */
264 scvidprobe(int unit, int flags, int cons)
267 * Access the video adapter driver through the back door!
268 * Video adapter drivers need to be configured before syscons.
269 * However, when syscons is being probed as the low-level console,
270 * they have not been initialized yet. We force them to initialize
271 * themselves here. XXX
273 vid_configure(cons ? VIO_PROBE_ONLY : 0);
275 return (vid_find_adapter("*", unit) >= 0);
278 /* probe the keyboard, return TRUE if found */
280 sckbdprobe(int unit, int flags, int cons)
282 /* access the keyboard driver through the backdoor! */
283 kbd_configure(cons ? KB_CONF_PROBE_ONLY : 0);
285 return (kbd_find_keyboard("*", unit) >= 0);
289 *adapter_name(video_adapter_t *adp)
295 { KD_MONO, { "MDA", "MDA" } },
296 { KD_HERCULES, { "Hercules", "Hercules" } },
297 { KD_CGA, { "CGA", "CGA" } },
298 { KD_EGA, { "EGA", "EGA (mono)" } },
299 { KD_VGA, { "VGA", "VGA (mono)" } },
300 { KD_PC98, { "PC-98x1", "PC-98x1" } },
301 { KD_TGA, { "TGA", "TGA" } },
302 { -1, { "Unknown", "Unknown" } },
306 for (i = 0; names[i].type != -1; ++i)
307 if (names[i].type == adp->va_type)
309 return names[i].name[(adp->va_flags & V_ADP_COLOR) ? 0 : 1];
313 sc_alloc_tty(struct cdev *dev)
317 tp = dev->si_tty = ttyalloc();
318 ttyinitmode(tp, 1, 0);
319 tp->t_oproc = scstart;
320 tp->t_param = scparam;
321 tp->t_stop = nottystop;
327 sc_attach_unit(int unit, int flags)
337 flags &= ~SC_KERNEL_CONSOLE;
339 if (sc_console_unit == unit) {
341 * If this unit is being used as the system console, we need to
342 * adjust some variables and buffers before and after scinit().
344 /* assert(sc_console != NULL) */
345 flags |= SC_KERNEL_CONSOLE;
350 if (sc_console->tsw->te_size > 0) {
351 /* assert(sc_console->ts != NULL); */
352 kernel_console_ts = sc_console->ts;
353 sc_console->ts = malloc(sc_console->tsw->te_size,
355 bcopy(kernel_console_ts, sc_console->ts, sc_console->tsw->te_size);
356 (*sc_console->tsw->te_default_attr)(sc_console,
357 user_default.std_color,
358 user_default.rev_color);
364 sc = sc_get_softc(unit, flags & SC_KERNEL_CONSOLE);
366 scp = sc_get_stat(sc->dev[0]);
367 if (sc_console == NULL) /* sc_console_unit < 0 */
371 if ((sc->config & SC_VESA800X600)
372 && ((*vidsw[sc->adapter]->get_info)(sc->adp, M_VESA_800x600, &info) == 0)) {
374 if (sc->flags & SC_SPLASH_SCRN)
375 splash_term(sc->adp);
377 sc_set_graphics_mode(scp, NULL, M_VESA_800x600);
378 sc_set_pixel_mode(scp, NULL, COL, ROW, 16, 8);
379 sc->initial_mode = M_VESA_800x600;
381 /* put up the splash again! */
382 if (sc->flags & SC_SPLASH_SCRN)
383 splash_init(sc->adp, scsplash_callback, sc);
386 #endif /* SC_PIXEL_MODE */
388 /* initialize cursor */
390 update_cursor_image(scp);
392 /* get screen update going */
395 /* set up the keyboard */
396 kbd_ioctl(sc->kbd, KDSKBMODE, (caddr_t)&scp->kbd_mode);
397 update_kbd_state(scp, scp->status, LOCK_MASK);
399 printf("%s%d: %s <%d virtual consoles, flags=0x%x>\n",
400 SC_DRIVER_NAME, unit, adapter_name(sc->adp), sc->vtys, sc->config);
402 printf("%s%d:", SC_DRIVER_NAME, unit);
403 if (sc->adapter >= 0)
404 printf(" fb%d", sc->adapter);
405 if (sc->keyboard >= 0)
406 printf(", kbd%d", sc->keyboard);
408 printf(", terminal emulator: %s (%s)",
409 scp->tsw->te_name, scp->tsw->te_desc);
413 /* register a shutdown callback for the kernel console */
414 if (sc_console_unit == unit)
415 EVENTHANDLER_REGISTER(shutdown_pre_sync, scshutdown,
416 (void *)(uintptr_t)unit, SHUTDOWN_PRI_DEFAULT);
418 for (vc = 0; vc < sc->vtys; vc++) {
419 if (sc->dev[vc] == NULL) {
420 sc->dev[vc] = make_dev(&sc_cdevsw, vc + unit * MAXCONS,
421 UID_ROOT, GID_WHEEL, 0600, "ttyv%r", vc + unit * MAXCONS);
422 sc_alloc_tty(sc->dev[vc]);
423 if (vc == 0 && sc->dev == main_devs)
424 SC_STAT(sc->dev[0]) = &main_console;
427 * The first vty already has struct tty and scr_stat initialized
428 * in scinit(). The other vtys will have these structs when
433 dev = make_dev(&sc_cdevsw, SC_CONSOLECTL,
434 UID_ROOT, GID_WHEEL, 0600, "consolectl");
435 sc_console_tty = sc_alloc_tty(dev);
436 ttyconsolemode(sc_console_tty, 0);
437 SC_STAT(dev) = sc_console;
450 * As soon as malloc() becomes functional, we had better allocate
451 * various buffers for the kernel console.
454 if (sc_console_unit < 0) /* sc_console == NULL */
457 /* copy the temporary buffer to the final buffer */
458 sc_alloc_scr_buffer(sc_console, FALSE, FALSE);
460 #ifndef SC_NO_CUTPASTE
461 sc_alloc_cut_buffer(sc_console, FALSE);
464 #ifndef SC_NO_HISTORY
465 /* initialize history buffer & pointers */
466 sc_alloc_history_buffer(sc_console, 0, 0, FALSE);
471 SYSINIT(sc_mem, SI_SUB_KMEM, SI_ORDER_ANY, scmeminit, NULL);
474 scdevtounit(struct cdev *dev)
476 int vty = SC_VTY(dev);
478 if (vty == SC_CONSOLECTL)
479 return ((sc_console != NULL) ? sc_console->sc->unit : -1);
480 else if ((vty < 0) || (vty >= MAXCONS*sc_max_unit()))
487 scopen(struct cdev *dev, int flag, int mode, struct thread *td)
489 int unit = scdevtounit(dev);
498 DPRINTF(5, ("scopen: dev:%s, unit:%d, vty:%d\n",
499 devtoname(dev), unit, SC_VTY(dev)));
502 sc = sc_get_softc(unit, (sc_console_unit == unit) ? SC_KERNEL_CONSOLE : 0);
506 if (!ISTTYOPEN(tp)) {
507 tp->t_termios = tp->t_init_in;
508 /* Use the current setting of the <-- key as default VERASE. */
509 /* If the Delete key is preferable, an stty is necessary */
511 if (sc->kbd != NULL) {
512 key.keynum = KEYCODE_BS;
513 kbd_ioctl(sc->kbd, GIO_KEYMAPENT, (caddr_t)&key);
514 tp->t_cc[VERASE] = key.key.map[0];
517 scparam(tp, &tp->t_termios);
521 if (tp->t_state & TS_XCLUDE && priv_check(td, PRIV_TTY_EXCLUSIVE))
524 error = ttyld_open(tp, dev);
526 scp = sc_get_stat(dev);
528 scp = SC_STAT(dev) = alloc_scp(sc, SC_VTY(dev));
530 sc_set_pixel_mode(scp, NULL, COL, ROW, 16, 8);
532 if (!tp->t_winsize.ws_col && !tp->t_winsize.ws_row) {
533 tp->t_winsize.ws_col = scp->xsize;
534 tp->t_winsize.ws_row = scp->ysize;
541 scclose(struct cdev *dev, int flag, int mode, struct thread *td)
543 struct tty *tp = dev->si_tty;
547 if (SC_VTY(dev) != SC_CONSOLECTL) {
548 scp = sc_get_stat(tp->t_dev);
549 /* were we in the middle of the VT switching process? */
550 DPRINTF(5, ("sc%d: scclose(), ", scp->sc->unit));
552 if ((scp == scp->sc->cur_scp) && (scp->sc->unit == sc_console_unit))
553 cnavailable(sc_consptr, TRUE);
554 if (finish_vt_rel(scp, TRUE, &s) == 0) /* force release */
555 DPRINTF(5, ("reset WAIT_REL, "));
556 if (finish_vt_acq(scp) == 0) /* force acknowledge */
557 DPRINTF(5, ("reset WAIT_ACQ, "));
559 if (scp == &main_console) {
562 scp->smode.mode = VT_AUTO;
565 sc_vtb_destroy(&scp->vtb);
567 sc_vtb_destroy(&scp->scr);
569 sc_free_history_buffer(scp, scp->ysize);
576 scp->smode.mode = VT_AUTO;
578 scp->kbd_mode = K_XLATE;
579 if (scp == scp->sc->cur_scp)
580 kbd_ioctl(scp->sc->kbd, KDSKBMODE, (caddr_t)&scp->kbd_mode);
581 DPRINTF(5, ("done.\n"));
584 ttyld_close(tp, flag);
591 scread(struct cdev *dev, struct uio *uio, int flag)
593 if (!sc_saver_keyb_only)
594 sc_touch_scrn_saver();
595 return ttyread(dev, uio, flag);
599 sckbdevent(keyboard_t *thiskbd, int event, void *arg)
607 sc = (sc_softc_t *)arg;
608 /* assert(thiskbd == sc->kbd) */
613 case KBDIO_UNLOADING:
616 kbd_release(thiskbd, (void *)&sc->keyboard);
623 * Loop while there is still input to get from the keyboard.
624 * I don't think this is nessesary, and it doesn't fix
625 * the Xaccel-2.1 keyboard hang, but it can't hurt. XXX
627 while ((c = scgetc(sc, SCGETC_NONBLOCK)) != NOKEY) {
629 cur_tty = VIRTUAL_TTY(sc, sc->cur_scp->index);
630 if (!ISTTYOPEN(cur_tty)) {
631 cur_tty = sc_console_tty;
632 if (!ISTTYOPEN(cur_tty))
636 if ((*sc->cur_scp->tsw->te_input)(sc->cur_scp, c, cur_tty))
639 switch (KEYFLAGS(c)) {
640 case 0x0000: /* normal key */
641 ttyld_rint(cur_tty, KEYCHAR(c));
643 case FKEY: /* function key, return string */
644 cp = kbd_get_fkeystr(thiskbd, KEYCHAR(c), &len);
647 ttyld_rint(cur_tty, *cp++);
650 case MKEY: /* meta is active, prepend ESC */
651 ttyld_rint(cur_tty, 0x1b);
652 ttyld_rint(cur_tty, KEYCHAR(c));
654 case BKEY: /* backtab fixed sequence (esc [ Z) */
655 ttyld_rint(cur_tty, 0x1b);
656 ttyld_rint(cur_tty, '[');
657 ttyld_rint(cur_tty, 'Z');
662 sc->cur_scp->status |= MOUSE_HIDDEN;
668 scparam(struct tty *tp, struct termios *t)
670 tp->t_ispeed = t->c_ispeed;
671 tp->t_ospeed = t->c_ospeed;
672 tp->t_cflag = t->c_cflag;
677 scioctl(struct cdev *dev, u_long cmd, caddr_t data, int flag, struct thread *td)
685 #if defined(COMPAT_FREEBSD6) || defined(COMPAT_FREEBSD5) || \
686 defined(COMPAT_FREEBSD4) || defined(COMPAT_43)
692 /* If there is a user_ioctl function call that first */
694 error = (*sc_user_ioctl)(dev, cmd, data, flag, td);
695 if (error != ENOIOCTL)
699 error = sc_vid_ioctl(tp, cmd, data, flag, td);
700 if (error != ENOIOCTL)
703 #ifndef SC_NO_HISTORY
704 error = sc_hist_ioctl(tp, cmd, data, flag, td);
705 if (error != ENOIOCTL)
709 #ifndef SC_NO_SYSMOUSE
710 error = sc_mouse_ioctl(tp, cmd, data, flag, td);
711 if (error != ENOIOCTL)
715 scp = sc_get_stat(tp->t_dev);
716 /* assert(scp != NULL) */
717 /* scp is sc_console, if SC_VTY(dev) == SC_CONSOLECTL. */
721 error = (*scp->tsw->te_ioctl)(scp, tp, cmd, data, flag, td);
722 if (error != ENOIOCTL)
726 switch (cmd) { /* process console hardware related ioctl's */
728 case GIO_ATTR: /* get current attributes */
729 /* this ioctl is not processed here, but in the terminal emulator */
732 case GIO_COLOR: /* is this a color console ? */
733 *(int *)data = (sc->adp->va_flags & V_ADP_COLOR) ? 1 : 0;
736 case CONS_BLANKTIME: /* set screen saver timeout (0 = no saver) */
737 if (*(int *)data < 0 || *(int *)data > MAX_BLANKTIME)
740 scrn_blank_time = *(int *)data;
741 run_scrn_saver = (scrn_blank_time != 0);
745 case CONS_CURSORTYPE: /* set cursor type (obsolete) */
747 *(int *)data &= CONS_CURSOR_ATTRS;
748 sc_change_cursor_shape(scp, *(int *)data, -1, -1);
752 case CONS_GETCURSORSHAPE: /* get cursor shape (new interface) */
753 if (((int *)data)[0] & CONS_LOCAL_CURSOR) {
754 ((int *)data)[0] = scp->curr_curs_attr.flags;
755 ((int *)data)[1] = scp->curr_curs_attr.base;
756 ((int *)data)[2] = scp->curr_curs_attr.height;
758 ((int *)data)[0] = sc->curs_attr.flags;
759 ((int *)data)[1] = sc->curs_attr.base;
760 ((int *)data)[2] = sc->curs_attr.height;
764 case CONS_SETCURSORSHAPE: /* set cursor shape (new interface) */
766 sc_change_cursor_shape(scp, ((int *)data)[0],
767 ((int *)data)[1], ((int *)data)[2]);
771 case CONS_BELLTYPE: /* set bell type sound/visual */
772 if ((*(int *)data) & CONS_VISUAL_BELL)
773 sc->flags |= SC_VISUAL_BELL;
775 sc->flags &= ~SC_VISUAL_BELL;
776 if ((*(int *)data) & CONS_QUIET_BELL)
777 sc->flags |= SC_QUIET_BELL;
779 sc->flags &= ~SC_QUIET_BELL;
782 case CONS_GETINFO: /* get current (virtual) console info */
784 vid_info_t *ptr = (vid_info_t*)data;
785 if (ptr->size == sizeof(struct vid_info)) {
786 ptr->m_num = sc->cur_scp->index;
787 ptr->font_size = scp->font_size;
788 ptr->mv_col = scp->xpos;
789 ptr->mv_row = scp->ypos;
790 ptr->mv_csz = scp->xsize;
791 ptr->mv_rsz = scp->ysize;
792 ptr->mv_hsz = (scp->history != NULL) ? scp->history->vtb_rows : 0;
794 * The following fields are filled by the terminal emulator. XXX
801 ptr->mv_grfc.fore = 0; /* not supported */
802 ptr->mv_grfc.back = 0; /* not supported */
803 ptr->mv_ovscan = scp->border;
804 if (scp == sc->cur_scp)
806 ptr->mk_keylock = scp->status & LOCK_MASK;
812 case CONS_GETVERS: /* get version number */
813 *(int*)data = 0x200; /* version 2.0 */
816 case CONS_IDLE: /* see if the screen has been idle */
818 * When the screen is in the GRAPHICS_MODE or UNKNOWN_MODE,
819 * the user process may have been writing something on the
820 * screen and syscons is not aware of it. Declare the screen
821 * is NOT idle if it is in one of these modes. But there is
822 * an exception to it; if a screen saver is running in the
823 * graphics mode in the current screen, we should say that the
824 * screen has been idle.
826 *(int *)data = (sc->flags & SC_SCRN_IDLE)
827 && (!ISGRAPHSC(sc->cur_scp)
828 || (sc->cur_scp->status & SAVER_RUNNING));
831 case CONS_SAVERMODE: /* set saver mode */
832 switch(*(int *)data) {
835 /* if a LKM screen saver is running, stop it first. */
836 scsplash_stick(FALSE);
837 saver_mode = *(int *)data;
840 if ((error = wait_scrn_saver_stop(NULL))) {
845 run_scrn_saver = TRUE;
846 if (saver_mode == CONS_USR_SAVER)
847 scp->status |= SAVER_RUNNING;
849 scp->status &= ~SAVER_RUNNING;
850 scsplash_stick(TRUE);
855 if ((saver_mode == CONS_USR_SAVER) && (scp->status & SAVER_RUNNING))
856 scp->status &= ~SAVER_RUNNING;
857 saver_mode = *(int *)data;
865 case CONS_SAVERSTART: /* immediately start/stop the screen saver */
867 * Note that this ioctl does not guarantee the screen saver
868 * actually starts or stops. It merely attempts to do so...
871 run_scrn_saver = (*(int *)data != 0);
873 sc->scrn_time_stamp -= scrn_blank_time;
877 case CONS_SCRSHOT: /* get a screen shot */
879 int retval, hist_rsz;
881 vm_offset_t frbp, hstp;
883 scrshot_t *ptr = (scrshot_t *)data;
884 void *outp = ptr->buf;
886 if (ptr->x < 0 || ptr->y < 0 || ptr->xsize < 0 || ptr->ysize < 0)
889 if (ISGRAPHSC(scp)) {
893 hist_rsz = (scp->history != NULL) ? scp->history->vtb_rows : 0;
894 if (((u_int)ptr->x + ptr->xsize) > scp->xsize ||
895 ((u_int)ptr->y + ptr->ysize) > (scp->ysize + hist_rsz)) {
900 lsize = scp->xsize * sizeof(u_int16_t);
901 csize = ptr->xsize * sizeof(u_int16_t);
902 /* Pointer to the last line of framebuffer */
903 frbp = scp->vtb.vtb_buffer + scp->ysize * lsize + ptr->x *
905 /* Pointer to the last line of target buffer */
906 outp = (char *)outp + ptr->ysize * csize;
907 /* Pointer to the last line of history buffer */
908 if (scp->history != NULL)
909 hstp = scp->history->vtb_buffer + sc_vtb_tail(scp->history) *
910 sizeof(u_int16_t) + ptr->x * sizeof(u_int16_t);
915 for (lnum = 0; lnum < (ptr->y + ptr->ysize); lnum++) {
916 if (lnum < scp->ysize) {
920 if (hstp < scp->history->vtb_buffer)
921 hstp += scp->history->vtb_rows * lsize;
926 outp = (char *)outp - csize;
927 retval = copyout((void *)frbp, outp, csize);
935 case VT_SETMODE: /* set screen switcher mode */
937 struct vt_mode *mode;
940 mode = (struct vt_mode *)data;
941 DPRINTF(5, ("%s%d: VT_SETMODE ", SC_DRIVER_NAME, sc->unit));
942 if (scp->smode.mode == VT_PROCESS) {
943 p1 = pfind(scp->pid);
944 if (scp->proc == p1 && scp->proc != td->td_proc) {
947 DPRINTF(5, ("error EPERM\n"));
954 if (mode->mode == VT_AUTO) {
955 scp->smode.mode = VT_AUTO;
958 DPRINTF(5, ("VT_AUTO, "));
959 if ((scp == sc->cur_scp) && (sc->unit == sc_console_unit))
960 cnavailable(sc_consptr, TRUE);
961 /* were we in the middle of the vty switching process? */
962 if (finish_vt_rel(scp, TRUE, &s) == 0)
963 DPRINTF(5, ("reset WAIT_REL, "));
964 if (finish_vt_acq(scp) == 0)
965 DPRINTF(5, ("reset WAIT_ACQ, "));
967 if (!ISSIGVALID(mode->relsig) || !ISSIGVALID(mode->acqsig)
968 || !ISSIGVALID(mode->frsig)) {
970 DPRINTF(5, ("error EINVAL\n"));
973 DPRINTF(5, ("VT_PROCESS %d, ", td->td_proc->p_pid));
974 bcopy(data, &scp->smode, sizeof(struct vt_mode));
975 scp->proc = td->td_proc;
976 scp->pid = scp->proc->p_pid;
977 if ((scp == sc->cur_scp) && (sc->unit == sc_console_unit))
978 cnavailable(sc_consptr, FALSE);
985 case VT_GETMODE: /* get screen switcher mode */
986 bcopy(&scp->smode, data, sizeof(struct vt_mode));
989 #if defined(COMPAT_FREEBSD6) || defined(COMPAT_FREEBSD5) || \
990 defined(COMPAT_FREEBSD4) || defined(COMPAT_43)
992 ival = IOCPARM_IVAL(data);
993 data = (caddr_t)&ival;
996 case VT_RELDISP: /* screen switcher ioctl */
999 * This must be the current vty which is in the VT_PROCESS
1002 if ((scp != sc->cur_scp) || (scp->smode.mode != VT_PROCESS)) {
1006 /* ...and this process is controlling it. */
1007 if (scp->proc != td->td_proc) {
1012 switch(*(int *)data) {
1013 case VT_FALSE: /* user refuses to release screen, abort */
1014 if ((error = finish_vt_rel(scp, FALSE, &s)) == 0)
1015 DPRINTF(5, ("%s%d: VT_FALSE\n", SC_DRIVER_NAME, sc->unit));
1017 case VT_TRUE: /* user has released screen, go on */
1018 if ((error = finish_vt_rel(scp, TRUE, &s)) == 0)
1019 DPRINTF(5, ("%s%d: VT_TRUE\n", SC_DRIVER_NAME, sc->unit));
1021 case VT_ACKACQ: /* acquire acknowledged, switch completed */
1022 if ((error = finish_vt_acq(scp)) == 0)
1023 DPRINTF(5, ("%s%d: VT_ACKACQ\n", SC_DRIVER_NAME, sc->unit));
1031 case VT_OPENQRY: /* return free virtual console */
1032 for (i = sc->first_vty; i < sc->first_vty + sc->vtys; i++) {
1033 tp = VIRTUAL_TTY(sc, i);
1034 if (!ISTTYOPEN(tp)) {
1035 *(int *)data = i + 1;
1041 #if defined(COMPAT_FREEBSD6) || defined(COMPAT_FREEBSD5) || \
1042 defined(COMPAT_FREEBSD4) || defined(COMPAT_43)
1044 ival = IOCPARM_IVAL(data);
1045 data = (caddr_t)&ival;
1048 case VT_ACTIVATE: /* switch to screen *data */
1049 i = (*(int *)data == 0) ? scp->index : (*(int *)data - 1);
1051 error = sc_clean_up(sc->cur_scp);
1055 return sc_switch_scr(sc, i);
1057 #if defined(COMPAT_FREEBSD6) || defined(COMPAT_FREEBSD5) || \
1058 defined(COMPAT_FREEBSD4) || defined(COMPAT_43)
1060 ival = IOCPARM_IVAL(data);
1061 data = (caddr_t)&ival;
1064 case VT_WAITACTIVE: /* wait for switch to occur */
1065 i = (*(int *)data == 0) ? scp->index : (*(int *)data - 1);
1066 if ((i < sc->first_vty) || (i >= sc->first_vty + sc->vtys))
1069 error = sc_clean_up(sc->cur_scp);
1073 scp = sc_get_stat(SC_DEV(sc, i));
1074 if (scp == scp->sc->cur_scp)
1076 while ((error=tsleep(&scp->smode, PZERO|PCATCH,
1077 "waitvt", 0)) == ERESTART) ;
1080 case VT_GETACTIVE: /* get active vty # */
1081 *(int *)data = sc->cur_scp->index + 1;
1084 case VT_GETINDEX: /* get this vty # */
1085 *(int *)data = scp->index + 1;
1088 case VT_LOCKSWITCH: /* prevent vty switching */
1089 if ((*(int *)data) & 0x01)
1090 sc->flags |= SC_SCRN_VTYLOCK;
1092 sc->flags &= ~SC_SCRN_VTYLOCK;
1095 case KDENABIO: /* allow io operations */
1096 error = priv_check(td, PRIV_IO);
1099 error = securelevel_gt(td->td_ucred, 0);
1103 td->td_frame->tf_eflags |= PSL_IOPL;
1104 #elif defined(__amd64__)
1105 td->td_frame->tf_rflags |= PSL_IOPL;
1109 case KDDISABIO: /* disallow io operations (default) */
1111 td->td_frame->tf_eflags &= ~PSL_IOPL;
1112 #elif defined(__amd64__)
1113 td->td_frame->tf_rflags &= ~PSL_IOPL;
1117 #if defined(COMPAT_FREEBSD6) || defined(COMPAT_FREEBSD5) || \
1118 defined(COMPAT_FREEBSD4) || defined(COMPAT_43)
1120 ival = IOCPARM_IVAL(data);
1121 data = (caddr_t)&ival;
1124 case KDSKBSTATE: /* set keyboard state (locks) */
1125 if (*(int *)data & ~LOCK_MASK)
1127 scp->status &= ~LOCK_MASK;
1128 scp->status |= *(int *)data;
1129 if (scp == sc->cur_scp)
1130 update_kbd_state(scp, scp->status, LOCK_MASK);
1133 case KDGKBSTATE: /* get keyboard state (locks) */
1134 if (scp == sc->cur_scp)
1135 save_kbd_state(scp);
1136 *(int *)data = scp->status & LOCK_MASK;
1139 case KDGETREPEAT: /* get keyboard repeat & delay rates */
1140 case KDSETREPEAT: /* set keyboard repeat & delay rates (new) */
1141 error = kbd_ioctl(sc->kbd, cmd, data);
1142 if (error == ENOIOCTL)
1146 #if defined(COMPAT_FREEBSD6) || defined(COMPAT_FREEBSD5) || \
1147 defined(COMPAT_FREEBSD4) || defined(COMPAT_43)
1149 ival = IOCPARM_IVAL(data);
1150 data = (caddr_t)&ival;
1153 case KDSETRAD: /* set keyboard repeat & delay rates (old) */
1154 if (*(int *)data & ~0x7f)
1156 error = kbd_ioctl(sc->kbd, KDSETRAD, data);
1157 if (error == ENOIOCTL)
1161 #if defined(COMPAT_FREEBSD6) || defined(COMPAT_FREEBSD5) || \
1162 defined(COMPAT_FREEBSD4) || defined(COMPAT_43)
1164 ival = IOCPARM_IVAL(data);
1165 data = (caddr_t)&ival;
1168 case KDSKBMODE: /* set keyboard mode */
1169 switch (*(int *)data) {
1170 case K_XLATE: /* switch to XLT ascii mode */
1171 case K_RAW: /* switch to RAW scancode mode */
1172 case K_CODE: /* switch to CODE mode */
1173 scp->kbd_mode = *(int *)data;
1174 if (scp == sc->cur_scp)
1175 kbd_ioctl(sc->kbd, KDSKBMODE, data);
1182 case KDGKBMODE: /* get keyboard mode */
1183 *(int *)data = scp->kbd_mode;
1187 error = kbd_ioctl(sc->kbd, cmd, data);
1188 if (error == ENOIOCTL)
1192 #if defined(COMPAT_FREEBSD6) || defined(COMPAT_FREEBSD5) || \
1193 defined(COMPAT_FREEBSD4) || defined(COMPAT_43)
1195 ival = IOCPARM_IVAL(data);
1196 data = (caddr_t)&ival;
1199 case KDMKTONE: /* sound the bell */
1201 sc_bell(scp, (*(int*)data)&0xffff,
1202 (((*(int*)data)>>16)&0xffff)*hz/1000);
1204 sc_bell(scp, scp->bell_pitch, scp->bell_duration);
1207 #if defined(COMPAT_FREEBSD6) || defined(COMPAT_FREEBSD5) || \
1208 defined(COMPAT_FREEBSD4) || defined(COMPAT_43)
1210 ival = IOCPARM_IVAL(data);
1211 data = (caddr_t)&ival;
1214 case KIOCSOUND: /* make tone (*data) hz */
1215 if (scp == sc->cur_scp) {
1217 return sc_tone(*(int *)data);
1223 case KDGKBTYPE: /* get keyboard type */
1224 error = kbd_ioctl(sc->kbd, cmd, data);
1225 if (error == ENOIOCTL) {
1226 /* always return something? XXX */
1231 #if defined(COMPAT_FREEBSD6) || defined(COMPAT_FREEBSD5) || \
1232 defined(COMPAT_FREEBSD4) || defined(COMPAT_43)
1234 ival = IOCPARM_IVAL(data);
1235 data = (caddr_t)&ival;
1238 case KDSETLED: /* set keyboard LED status */
1239 if (*(int *)data & ~LED_MASK) /* FIXME: LOCK_MASK? */
1241 scp->status &= ~LED_MASK;
1242 scp->status |= *(int *)data;
1243 if (scp == sc->cur_scp)
1244 update_kbd_leds(scp, scp->status);
1247 case KDGETLED: /* get keyboard LED status */
1248 if (scp == sc->cur_scp)
1249 save_kbd_state(scp);
1250 *(int *)data = scp->status & LED_MASK;
1253 case KBADDKBD: /* add/remove keyboard to/from mux */
1255 error = kbd_ioctl(sc->kbd, cmd, data);
1256 if (error == ENOIOCTL)
1260 #if defined(COMPAT_FREEBSD6) || defined(COMPAT_FREEBSD5) || \
1261 defined(COMPAT_FREEBSD4) || defined(COMPAT_43)
1263 ival = IOCPARM_IVAL(data);
1264 data = (caddr_t)&ival;
1267 case CONS_SETKBD: /* set the new keyboard */
1272 newkbd = kbd_get_keyboard(*(int *)data);
1273 if (newkbd == NULL) {
1278 if (sc->kbd != newkbd) {
1279 i = kbd_allocate(newkbd->kb_name, newkbd->kb_unit,
1280 (void *)&sc->keyboard, sckbdevent, sc);
1281 /* i == newkbd->kb_index */
1283 if (sc->kbd != NULL) {
1284 save_kbd_state(sc->cur_scp);
1285 kbd_release(sc->kbd, (void *)&sc->keyboard);
1287 sc->kbd = kbd_get_keyboard(i); /* sc->kbd == newkbd */
1289 kbd_ioctl(sc->kbd, KDSKBMODE,
1290 (caddr_t)&sc->cur_scp->kbd_mode);
1291 update_kbd_state(sc->cur_scp, sc->cur_scp->status,
1294 error = EPERM; /* XXX */
1301 case CONS_RELKBD: /* release the current keyboard */
1304 if (sc->kbd != NULL) {
1305 save_kbd_state(sc->cur_scp);
1306 error = kbd_release(sc->kbd, (void *)&sc->keyboard);
1315 case CONS_GETTERM: /* get the current terminal emulator info */
1319 if (((term_info_t *)data)->ti_index == 0) {
1322 sw = sc_term_match_by_number(((term_info_t *)data)->ti_index);
1325 strncpy(((term_info_t *)data)->ti_name, sw->te_name,
1326 sizeof(((term_info_t *)data)->ti_name));
1327 strncpy(((term_info_t *)data)->ti_desc, sw->te_desc,
1328 sizeof(((term_info_t *)data)->ti_desc));
1329 ((term_info_t *)data)->ti_flags = 0;
1332 ((term_info_t *)data)->ti_name[0] = '\0';
1333 ((term_info_t *)data)->ti_desc[0] = '\0';
1334 ((term_info_t *)data)->ti_flags = 0;
1339 case CONS_SETTERM: /* set the current terminal emulator */
1341 error = sc_init_emulator(scp, ((term_info_t *)data)->ti_name);
1342 /* FIXME: what if scp == sc_console! XXX */
1346 case GIO_SCRNMAP: /* get output translation table */
1347 bcopy(&sc->scr_map, data, sizeof(sc->scr_map));
1350 case PIO_SCRNMAP: /* set output translation table */
1351 bcopy(data, &sc->scr_map, sizeof(sc->scr_map));
1352 for (i=0; i<sizeof(sc->scr_map); i++) {
1353 sc->scr_rmap[sc->scr_map[i]] = i;
1357 case GIO_KEYMAP: /* get keyboard translation table */
1358 case PIO_KEYMAP: /* set keyboard translation table */
1359 case GIO_DEADKEYMAP: /* get accent key translation table */
1360 case PIO_DEADKEYMAP: /* set accent key translation table */
1361 case GETFKEY: /* get function key string */
1362 case SETFKEY: /* set function key string */
1363 error = kbd_ioctl(sc->kbd, cmd, data);
1364 if (error == ENOIOCTL)
1368 #ifndef SC_NO_FONT_LOADING
1370 case PIO_FONT8x8: /* set 8x8 dot font */
1371 if (!ISFONTAVAIL(sc->adp->va_flags))
1373 bcopy(data, sc->font_8, 8*256);
1374 sc->fonts_loaded |= FONT_8;
1377 * Always use the font page #0. XXX
1378 * Don't load if the current font size is not 8x8.
1380 if (ISTEXTSC(sc->cur_scp) && (sc->cur_scp->font_size < 14))
1381 sc_load_font(sc->cur_scp, 0, 8, 8, sc->font_8, 0, 256);
1384 case GIO_FONT8x8: /* get 8x8 dot font */
1385 if (!ISFONTAVAIL(sc->adp->va_flags))
1387 if (sc->fonts_loaded & FONT_8) {
1388 bcopy(sc->font_8, data, 8*256);
1394 case PIO_FONT8x14: /* set 8x14 dot font */
1395 if (!ISFONTAVAIL(sc->adp->va_flags))
1397 bcopy(data, sc->font_14, 14*256);
1398 sc->fonts_loaded |= FONT_14;
1401 * Always use the font page #0. XXX
1402 * Don't load if the current font size is not 8x14.
1404 if (ISTEXTSC(sc->cur_scp)
1405 && (sc->cur_scp->font_size >= 14)
1406 && (sc->cur_scp->font_size < 16))
1407 sc_load_font(sc->cur_scp, 0, 14, 8, sc->font_14, 0, 256);
1410 case GIO_FONT8x14: /* get 8x14 dot font */
1411 if (!ISFONTAVAIL(sc->adp->va_flags))
1413 if (sc->fonts_loaded & FONT_14) {
1414 bcopy(sc->font_14, data, 14*256);
1420 case PIO_FONT8x16: /* set 8x16 dot font */
1421 if (!ISFONTAVAIL(sc->adp->va_flags))
1423 bcopy(data, sc->font_16, 16*256);
1424 sc->fonts_loaded |= FONT_16;
1427 * Always use the font page #0. XXX
1428 * Don't load if the current font size is not 8x16.
1430 if (ISTEXTSC(sc->cur_scp) && (sc->cur_scp->font_size >= 16))
1431 sc_load_font(sc->cur_scp, 0, 16, 8, sc->font_16, 0, 256);
1434 case GIO_FONT8x16: /* get 8x16 dot font */
1435 if (!ISFONTAVAIL(sc->adp->va_flags))
1437 if (sc->fonts_loaded & FONT_16) {
1438 bcopy(sc->font_16, data, 16*256);
1444 #endif /* SC_NO_FONT_LOADING */
1450 return (ttyioctl(dev, cmd, data, flag, td));
1454 scstart(struct tty *tp)
1458 u_char buf[PCBURST];
1459 scr_stat *scp = sc_get_stat(tp->t_dev);
1461 if (scp->status & SLKED ||
1462 (scp == scp->sc->cur_scp && scp->sc->blink_in_progress))
1465 if (!(tp->t_state & (TS_TIMEOUT | TS_BUSY | TS_TTSTOP))) {
1466 tp->t_state |= TS_BUSY;
1469 len = q_to_b(rbp, buf, PCBURST);
1471 sc_puts(scp, buf, len);
1474 tp->t_state &= ~TS_BUSY;
1481 sc_cnprobe(struct consdev *cp)
1486 cp->cn_pri = sc_get_cons_priority(&unit, &flags);
1488 /* a video card is always required */
1489 if (!scvidprobe(unit, flags, TRUE))
1490 cp->cn_pri = CN_DEAD;
1492 /* syscons will become console even when there is no keyboard */
1493 sckbdprobe(unit, flags, TRUE);
1495 if (cp->cn_pri == CN_DEAD)
1498 /* initialize required fields */
1499 sprintf(cp->cn_name, "consolectl");
1503 sc_cninit(struct consdev *cp)
1508 sc_get_cons_priority(&unit, &flags);
1509 scinit(unit, flags | SC_KERNEL_CONSOLE);
1510 sc_console_unit = unit;
1511 sc_console = sc_get_stat(sc_get_softc(unit, SC_KERNEL_CONSOLE)->dev[0]);
1516 sc_cnterm(struct consdev *cp)
1518 /* we are not the kernel console any more, release everything */
1520 if (sc_console_unit < 0)
1521 return; /* shouldn't happen */
1524 sc_clear_screen(sc_console);
1525 sccnupdate(sc_console);
1528 scterm(sc_console_unit, SC_KERNEL_CONSOLE);
1529 sc_console_unit = -1;
1534 sc_cnputc(struct consdev *cd, int c)
1537 scr_stat *scp = sc_console;
1539 #ifndef SC_NO_HISTORY
1541 #endif /* !SC_NO_HISTORY */
1544 /* assert(sc_console != NULL) */
1546 #ifndef SC_NO_HISTORY
1547 if (scp == scp->sc->cur_scp && scp->status & SLKED) {
1548 scp->status &= ~SLKED;
1549 update_kbd_state(scp, scp->status, SLKED);
1550 if (scp->status & BUFFER_SAVED) {
1551 if (!sc_hist_restore(scp))
1552 sc_remove_cutmarking(scp);
1553 scp->status &= ~BUFFER_SAVED;
1554 scp->status |= CURSOR_ENABLED;
1555 sc_draw_cursor_image(scp);
1557 tp = VIRTUAL_TTY(scp->sc, scp->index);
1561 #endif /* !SC_NO_HISTORY */
1564 if (kernel_console_ts != NULL)
1565 scp->ts = kernel_console_ts;
1567 sc_puts(scp, buf, 1);
1570 s = spltty(); /* block sckbdevent and scrn_timer */
1576 sc_cngetc(struct consdev *cd)
1578 return sccngetch(SCGETC_NONBLOCK);
1582 sccngetch(int flags)
1584 static struct fkeytab fkey;
1589 int s = spltty(); /* block sckbdevent and scrn_timer while we poll */
1592 /* assert(sc_console != NULL) */
1595 * Stop the screen saver and update the screen if necessary.
1596 * What if we have been running in the screen saver code... XXX
1598 sc_touch_scrn_saver();
1599 scp = sc_console->sc->cur_scp; /* XXX */
1602 if (fkeycp < fkey.len) {
1604 return fkey.str[fkeycp++];
1607 if (scp->sc->kbd == NULL) {
1613 * Make sure the keyboard is accessible even when the kbd device
1614 * driver is disabled.
1616 kbd_enable(scp->sc->kbd);
1618 /* we shall always use the keyboard in the XLATE mode here */
1619 cur_mode = scp->kbd_mode;
1620 scp->kbd_mode = K_XLATE;
1621 kbd_ioctl(scp->sc->kbd, KDSKBMODE, (caddr_t)&scp->kbd_mode);
1623 kbd_poll(scp->sc->kbd, TRUE);
1624 c = scgetc(scp->sc, SCGETC_CN | flags);
1625 kbd_poll(scp->sc->kbd, FALSE);
1627 scp->kbd_mode = cur_mode;
1628 kbd_ioctl(scp->sc->kbd, KDSKBMODE, (caddr_t)&scp->kbd_mode);
1629 kbd_disable(scp->sc->kbd);
1632 switch (KEYFLAGS(c)) {
1633 case 0: /* normal char */
1635 case FKEY: /* function key */
1636 p = kbd_get_fkeystr(scp->sc->kbd, KEYCHAR(c), (size_t *)&fkeycp);
1638 if ((p != NULL) && (fkey.len > 0)) {
1639 bcopy(p, fkey.str, fkey.len);
1653 sccnupdate(scr_stat *scp)
1655 /* this is a cut-down version of scrn_timer()... */
1657 if (scp->sc->font_loading_in_progress)
1660 if (debugger > 0 || panicstr || shutdown_in_progress) {
1661 sc_touch_scrn_saver();
1662 } else if (scp != scp->sc->cur_scp) {
1666 if (!run_scrn_saver)
1667 scp->sc->flags &= ~SC_SCRN_IDLE;
1669 if ((saver_mode != CONS_LKM_SAVER) || !(scp->sc->flags & SC_SCRN_IDLE))
1670 if (scp->sc->flags & SC_SCRN_BLANKED)
1671 stop_scrn_saver(scp->sc, current_saver);
1674 if (scp != scp->sc->cur_scp || scp->sc->blink_in_progress
1675 || scp->sc->switch_in_progress)
1678 * FIXME: unlike scrn_timer(), we call scrn_update() from here even
1679 * when write_in_progress is non-zero. XXX
1682 if (!ISGRAPHSC(scp) && !(scp->sc->flags & SC_SCRN_BLANKED))
1683 scrn_update(scp, TRUE);
1687 scrn_timer(void *arg)
1690 static int kbd_interval = 0;
1698 again = (arg != NULL);
1700 sc = (sc_softc_t *)arg;
1701 else if (sc_console != NULL)
1702 sc = sc_console->sc;
1706 /* don't do anything when we are performing some I/O operations */
1707 if (sc->font_loading_in_progress) {
1709 timeout(scrn_timer, sc, hz / 10);
1715 if ((sc->kbd == NULL) && (sc->config & SC_AUTODETECT_KBD)) {
1716 /* try to allocate a keyboard automatically */
1717 if (++kbd_interval >= 25) {
1718 sc->keyboard = sc_allocate_keyboard(sc, -1);
1719 if (sc->keyboard >= 0) {
1720 sc->kbd = kbd_get_keyboard(sc->keyboard);
1721 kbd_ioctl(sc->kbd, KDSKBMODE,
1722 (caddr_t)&sc->cur_scp->kbd_mode);
1723 update_kbd_state(sc->cur_scp, sc->cur_scp->status,
1731 /* find the vty to update */
1734 /* should we stop the screen saver? */
1735 getmicrouptime(&tv);
1736 if (debugger > 0 || panicstr || shutdown_in_progress)
1737 sc_touch_scrn_saver();
1738 if (run_scrn_saver) {
1739 if (tv.tv_sec > sc->scrn_time_stamp + scrn_blank_time)
1740 sc->flags |= SC_SCRN_IDLE;
1742 sc->flags &= ~SC_SCRN_IDLE;
1744 sc->scrn_time_stamp = tv.tv_sec;
1745 sc->flags &= ~SC_SCRN_IDLE;
1746 if (scrn_blank_time > 0)
1747 run_scrn_saver = TRUE;
1750 if ((saver_mode != CONS_LKM_SAVER) || !(sc->flags & SC_SCRN_IDLE))
1751 if (sc->flags & SC_SCRN_BLANKED)
1752 stop_scrn_saver(sc, current_saver);
1755 /* should we just return ? */
1756 if (sc->blink_in_progress || sc->switch_in_progress
1757 || sc->write_in_progress) {
1759 timeout(scrn_timer, sc, hz / 10);
1764 /* Update the screen */
1765 scp = sc->cur_scp; /* cur_scp may have changed... */
1766 if (!ISGRAPHSC(scp) && !(sc->flags & SC_SCRN_BLANKED))
1767 scrn_update(scp, TRUE);
1770 /* should we activate the screen saver? */
1771 if ((saver_mode == CONS_LKM_SAVER) && (sc->flags & SC_SCRN_IDLE))
1772 if (!ISGRAPHSC(scp) || (sc->flags & SC_SCRN_BLANKED))
1773 (*current_saver)(sc, TRUE);
1777 timeout(scrn_timer, sc, hz / 25);
1782 and_region(int *s1, int *e1, int s2, int e2)
1784 if (*e1 < s2 || e2 < *s1)
1786 *s1 = imax(*s1, s2);
1787 *e1 = imin(*e1, e2);
1792 scrn_update(scr_stat *scp, int show_cursor)
1799 /* assert(scp == scp->sc->cur_scp) */
1801 SC_VIDEO_LOCK(scp->sc);
1803 #ifndef SC_NO_CUTPASTE
1804 /* remove the previous mouse pointer image if necessary */
1805 if (scp->status & MOUSE_VISIBLE) {
1807 e = scp->mouse_pos + scp->xsize + 1;
1808 if ((scp->status & (MOUSE_MOVED | MOUSE_HIDDEN))
1809 || and_region(&s, &e, scp->start, scp->end)
1810 || ((scp->status & CURSOR_ENABLED) &&
1811 (scp->cursor_pos != scp->cursor_oldpos) &&
1812 (and_region(&s, &e, scp->cursor_pos, scp->cursor_pos)
1813 || and_region(&s, &e, scp->cursor_oldpos, scp->cursor_oldpos)))) {
1814 sc_remove_mouse_image(scp);
1815 if (scp->end >= scp->xsize*scp->ysize)
1816 scp->end = scp->xsize*scp->ysize - 1;
1819 #endif /* !SC_NO_CUTPASTE */
1823 if (scp->end >= scp->xsize*scp->ysize) {
1824 printf("scrn_update(): scp->end %d > size_of_screen!!\n", scp->end);
1825 scp->end = scp->xsize*scp->ysize - 1;
1827 if (scp->start < 0) {
1828 printf("scrn_update(): scp->start %d < 0\n", scp->start);
1833 /* update screen image */
1834 if (scp->start <= scp->end) {
1835 if (scp->mouse_cut_end >= 0) {
1836 /* there is a marked region for cut & paste */
1837 if (scp->mouse_cut_start <= scp->mouse_cut_end) {
1838 start = scp->mouse_cut_start;
1839 end = scp->mouse_cut_end;
1841 start = scp->mouse_cut_end;
1842 end = scp->mouse_cut_start - 1;
1846 /* does the cut-mark region overlap with the update region? */
1847 if (and_region(&s, &e, scp->start, scp->end)) {
1848 (*scp->rndr->draw)(scp, s, e - s + 1, TRUE);
1851 if (and_region(&s, &e, scp->start, scp->end))
1852 (*scp->rndr->draw)(scp, s, e - s + 1, FALSE);
1854 e = scp->xsize*scp->ysize - 1;
1855 if (and_region(&s, &e, scp->start, scp->end))
1856 (*scp->rndr->draw)(scp, s, e - s + 1, FALSE);
1858 (*scp->rndr->draw)(scp, scp->start,
1859 scp->end - scp->start + 1, FALSE);
1862 (*scp->rndr->draw)(scp, scp->start,
1863 scp->end - scp->start + 1, FALSE);
1867 /* we are not to show the cursor and the mouse pointer... */
1870 scp->start = scp->xsize*scp->ysize - 1;
1871 SC_VIDEO_UNLOCK(scp->sc);
1875 /* update cursor image */
1876 if (scp->status & CURSOR_ENABLED) {
1879 /* did cursor move since last time ? */
1880 if (scp->cursor_pos != scp->cursor_oldpos) {
1881 /* do we need to remove old cursor image ? */
1882 if (!and_region(&s, &e, scp->cursor_oldpos, scp->cursor_oldpos))
1883 sc_remove_cursor_image(scp);
1884 sc_draw_cursor_image(scp);
1886 if (and_region(&s, &e, scp->cursor_pos, scp->cursor_pos))
1887 /* cursor didn't move, but has been overwritten */
1888 sc_draw_cursor_image(scp);
1889 else if (scp->curs_attr.flags & CONS_BLINK_CURSOR)
1890 /* if it's a blinking cursor, update it */
1891 (*scp->rndr->blink_cursor)(scp, scp->cursor_pos,
1892 sc_inside_cutmark(scp,
1897 #ifndef SC_NO_CUTPASTE
1898 /* update "pseudo" mouse pointer image */
1899 if (scp->sc->flags & SC_MOUSE_ENABLED) {
1900 if (!(scp->status & (MOUSE_VISIBLE | MOUSE_HIDDEN))) {
1901 scp->status &= ~MOUSE_MOVED;
1902 sc_draw_mouse_image(scp);
1905 #endif /* SC_NO_CUTPASTE */
1908 scp->start = scp->xsize*scp->ysize - 1;
1910 SC_VIDEO_UNLOCK(scp->sc);
1915 scsplash_callback(int event, void *arg)
1920 sc = (sc_softc_t *)arg;
1924 if (add_scrn_saver(scsplash_saver) == 0) {
1925 sc->flags &= ~SC_SAVER_FAILED;
1926 run_scrn_saver = TRUE;
1927 if (cold && !(boothowto & RB_VERBOSE)) {
1928 scsplash_stick(TRUE);
1929 (*current_saver)(sc, TRUE);
1935 if (current_saver == scsplash_saver) {
1936 scsplash_stick(FALSE);
1937 error = remove_scrn_saver(scsplash_saver);
1949 scsplash_saver(sc_softc_t *sc, int show)
1951 static int busy = FALSE;
1960 if (!(sc->flags & SC_SAVER_FAILED)) {
1961 if (!(sc->flags & SC_SCRN_BLANKED))
1962 set_scrn_saver_mode(scp, -1, NULL, 0);
1963 switch (splash(sc->adp, TRUE)) {
1964 case 0: /* succeeded */
1966 case EAGAIN: /* try later */
1967 restore_scrn_saver_mode(scp, FALSE);
1968 sc_touch_scrn_saver(); /* XXX */
1971 sc->flags |= SC_SAVER_FAILED;
1972 scsplash_stick(FALSE);
1973 restore_scrn_saver_mode(scp, TRUE);
1974 printf("scsplash_saver(): failed to put up the image\n");
1978 } else if (!sticky_splash) {
1979 if ((sc->flags & SC_SCRN_BLANKED) && (splash(sc->adp, FALSE) == 0))
1980 restore_scrn_saver_mode(scp, TRUE);
1986 add_scrn_saver(void (*this_saver)(sc_softc_t *, int))
1991 if (current_saver != none_saver) {
1992 error = remove_scrn_saver(current_saver);
1997 if (current_saver != none_saver)
2000 run_scrn_saver = FALSE;
2001 saver_mode = CONS_LKM_SAVER;
2002 current_saver = this_saver;
2007 remove_scrn_saver(void (*this_saver)(sc_softc_t *, int))
2009 if (current_saver != this_saver)
2014 * In order to prevent `current_saver' from being called by
2015 * the timeout routine `scrn_timer()' while we manipulate
2016 * the saver list, we shall set `current_saver' to `none_saver'
2017 * before stopping the current saver, rather than blocking by `splXX()'.
2019 current_saver = none_saver;
2021 stop_scrn_saver(this_saver);
2024 /* unblank all blanked screens */
2025 wait_scrn_saver_stop(NULL);
2029 current_saver = none_saver;
2034 set_scrn_saver_mode(scr_stat *scp, int mode, u_char *pal, int border)
2038 /* assert(scp == scp->sc->cur_scp) */
2040 if (!ISGRAPHSC(scp))
2041 sc_remove_cursor_image(scp);
2042 scp->splash_save_mode = scp->mode;
2043 scp->splash_save_status = scp->status & (GRAPHICS_MODE | PIXEL_MODE);
2044 scp->status &= ~(GRAPHICS_MODE | PIXEL_MODE);
2045 scp->status |= (UNKNOWN_MODE | SAVER_RUNNING);
2046 scp->sc->flags |= SC_SCRN_BLANKED;
2052 if (set_mode(scp) == 0) {
2053 if (scp->sc->adp->va_info.vi_flags & V_INFO_GRAPHICS)
2054 scp->status |= GRAPHICS_MODE;
2055 #ifndef SC_NO_PALETTE_LOADING
2057 load_palette(scp->sc->adp, pal);
2059 sc_set_border(scp, border);
2063 scp->mode = scp->splash_save_mode;
2064 scp->status &= ~(UNKNOWN_MODE | SAVER_RUNNING);
2065 scp->status |= scp->splash_save_status;
2072 restore_scrn_saver_mode(scr_stat *scp, int changemode)
2078 /* assert(scp == scp->sc->cur_scp) */
2081 status = scp->status;
2082 scp->mode = scp->splash_save_mode;
2083 scp->status &= ~(UNKNOWN_MODE | SAVER_RUNNING);
2084 scp->status |= scp->splash_save_status;
2085 scp->sc->flags &= ~SC_SCRN_BLANKED;
2087 if (!ISGRAPHSC(scp))
2088 sc_draw_cursor_image(scp);
2093 if (set_mode(scp) == 0) {
2094 #ifndef SC_NO_PALETTE_LOADING
2095 load_palette(scp->sc->adp, scp->sc->palette);
2102 scp->status = status;
2109 stop_scrn_saver(sc_softc_t *sc, void (*saver)(sc_softc_t *, int))
2111 (*saver)(sc, FALSE);
2112 run_scrn_saver = FALSE;
2113 /* the screen saver may have chosen not to stop after all... */
2114 if (sc->flags & SC_SCRN_BLANKED)
2117 mark_all(sc->cur_scp);
2118 if (sc->delayed_next_scr)
2119 sc_switch_scr(sc, sc->delayed_next_scr - 1);
2121 wakeup(&scrn_blanked);
2125 wait_scrn_saver_stop(sc_softc_t *sc)
2129 while (scrn_blanked > 0) {
2130 run_scrn_saver = FALSE;
2131 if (sc && !(sc->flags & SC_SCRN_BLANKED)) {
2135 error = tsleep(&scrn_blanked, PZERO | PCATCH, "scrsav", 0);
2136 if ((error != 0) && (error != ERESTART))
2139 run_scrn_saver = FALSE;
2142 #endif /* DEV_SPLASH */
2145 sc_touch_scrn_saver(void)
2147 scsplash_stick(FALSE);
2148 run_scrn_saver = FALSE;
2152 sc_switch_scr(sc_softc_t *sc, u_int next_scr)
2159 DPRINTF(5, ("sc0: sc_switch_scr() %d ", next_scr + 1));
2161 if (sc->cur_scp == NULL)
2164 /* prevent switch if previously requested */
2165 if (sc->flags & SC_SCRN_VTYLOCK) {
2166 sc_bell(sc->cur_scp, sc->cur_scp->bell_pitch,
2167 sc->cur_scp->bell_duration);
2171 /* delay switch if the screen is blanked or being updated */
2172 if ((sc->flags & SC_SCRN_BLANKED) || sc->write_in_progress
2173 || sc->blink_in_progress) {
2174 sc->delayed_next_scr = next_scr + 1;
2175 sc_touch_scrn_saver();
2176 DPRINTF(5, ("switch delayed\n"));
2179 sc->delayed_next_scr = 0;
2182 cur_scp = sc->cur_scp;
2184 /* we are in the middle of the vty switching process... */
2185 if (sc->switch_in_progress
2186 && (cur_scp->smode.mode == VT_PROCESS)
2188 p = pfind(cur_scp->pid);
2189 if (cur_scp->proc != p) {
2193 * The controlling process has died!!. Do some clean up.
2194 * NOTE:`cur_scp->proc' and `cur_scp->smode.mode'
2195 * are not reset here yet; they will be cleared later.
2197 DPRINTF(5, ("cur_scp controlling process %d died, ",
2199 if (cur_scp->status & SWITCH_WAIT_REL) {
2201 * Force the previous switch to finish, but return now
2204 DPRINTF(5, ("reset WAIT_REL, "));
2205 finish_vt_rel(cur_scp, TRUE, &s);
2207 DPRINTF(5, ("finishing previous switch\n"));
2209 } else if (cur_scp->status & SWITCH_WAIT_ACQ) {
2210 /* let's assume screen switch has been completed. */
2211 DPRINTF(5, ("reset WAIT_ACQ, "));
2212 finish_vt_acq(cur_scp);
2215 * We are in between screen release and acquisition, and
2216 * reached here via scgetc() or scrn_timer() which has
2217 * interrupted exchange_scr(). Don't do anything stupid.
2219 DPRINTF(5, ("waiting nothing, "));
2225 * The controlling process is alive, but not responding...
2226 * It is either buggy or it may be just taking time.
2227 * The following code is a gross kludge to cope with this
2228 * problem for which there is no clean solution. XXX
2230 if (cur_scp->status & SWITCH_WAIT_REL) {
2231 switch (sc->switch_in_progress++) {
2235 DPRINTF(5, ("sending relsig again, "));
2236 signal_vt_rel(cur_scp);
2243 * Act as if the controlling program returned
2246 DPRINTF(5, ("force reset WAIT_REL, "));
2247 finish_vt_rel(cur_scp, FALSE, &s);
2249 DPRINTF(5, ("act as if VT_FALSE was seen\n"));
2252 } else if (cur_scp->status & SWITCH_WAIT_ACQ) {
2253 switch (sc->switch_in_progress++) {
2257 DPRINTF(5, ("sending acqsig again, "));
2258 signal_vt_acq(cur_scp);
2264 /* clear the flag and finish the previous switch */
2265 DPRINTF(5, ("force reset WAIT_ACQ, "));
2266 finish_vt_acq(cur_scp);
2274 * Return error if an invalid argument is given, or vty switch
2275 * is still in progress.
2277 if ((next_scr < sc->first_vty) || (next_scr >= sc->first_vty + sc->vtys)
2278 || sc->switch_in_progress) {
2280 sc_bell(cur_scp, bios_value.bell_pitch, BELL_DURATION);
2281 DPRINTF(5, ("error 1\n"));
2286 * Don't allow switching away from the graphics mode vty
2287 * if the switch mode is VT_AUTO, unless the next vty is the same
2288 * as the current or the current vty has been closed (but showing).
2290 tp = VIRTUAL_TTY(sc, cur_scp->index);
2291 if ((cur_scp->index != next_scr)
2293 && (cur_scp->smode.mode == VT_AUTO)
2294 && ISGRAPHSC(cur_scp)) {
2296 sc_bell(cur_scp, bios_value.bell_pitch, BELL_DURATION);
2297 DPRINTF(5, ("error, graphics mode\n"));
2302 * Is the wanted vty open? Don't allow switching to a closed vty.
2303 * If we are in DDB, don't switch to a vty in the VT_PROCESS mode.
2304 * Note that we always allow the user to switch to the kernel
2305 * console even if it is closed.
2307 if ((sc_console == NULL) || (next_scr != sc_console->index)) {
2308 tp = VIRTUAL_TTY(sc, next_scr);
2309 if (!ISTTYOPEN(tp)) {
2311 sc_bell(cur_scp, bios_value.bell_pitch, BELL_DURATION);
2312 DPRINTF(5, ("error 2, requested vty isn't open!\n"));
2315 if ((debugger > 0) && (SC_STAT(tp->t_dev)->smode.mode == VT_PROCESS)) {
2317 DPRINTF(5, ("error 3, requested vty is in the VT_PROCESS mode\n"));
2322 /* this is the start of vty switching process... */
2323 ++sc->switch_in_progress;
2324 sc->old_scp = cur_scp;
2325 sc->new_scp = sc_get_stat(SC_DEV(sc, next_scr));
2326 if (sc->new_scp == sc->old_scp) {
2327 sc->switch_in_progress = 0;
2329 * XXX wakeup() calls mtx_lock(&sched_lock) which will hang if
2330 * sched_lock is in an in-between state, e.g., when we stop at
2331 * a breakpoint at fork_exit. It has always been wrong to call
2332 * wakeup() when the debugger is active. In RELENG_4, wakeup()
2333 * is supposed to be locked by splhigh(), but the debugger may
2334 * be invoked at splhigh().
2337 wakeup(&sc->new_scp->smode);
2339 DPRINTF(5, ("switch done (new == old)\n"));
2343 /* has controlling process died? */
2344 vt_proc_alive(sc->old_scp);
2345 vt_proc_alive(sc->new_scp);
2347 /* wait for the controlling process to release the screen, if necessary */
2348 if (signal_vt_rel(sc->old_scp)) {
2353 /* go set up the new vty screen */
2358 /* wake up processes waiting for this vty */
2360 wakeup(&sc->cur_scp->smode);
2362 /* wait for the controlling process to acknowledge, if necessary */
2363 if (signal_vt_acq(sc->cur_scp)) {
2368 sc->switch_in_progress = 0;
2369 if (sc->unit == sc_console_unit)
2370 cnavailable(sc_consptr, TRUE);
2372 DPRINTF(5, ("switch done\n"));
2378 do_switch_scr(sc_softc_t *sc, int s)
2380 vt_proc_alive(sc->new_scp);
2385 /* sc->cur_scp == sc->new_scp */
2386 wakeup(&sc->cur_scp->smode);
2388 /* wait for the controlling process to acknowledge, if necessary */
2389 if (!signal_vt_acq(sc->cur_scp)) {
2390 sc->switch_in_progress = 0;
2391 if (sc->unit == sc_console_unit)
2392 cnavailable(sc_consptr, TRUE);
2399 vt_proc_alive(scr_stat *scp)
2404 if ((p = pfind(scp->pid)) != NULL)
2409 scp->smode.mode = VT_AUTO;
2410 DPRINTF(5, ("vt controlling process %d died\n", scp->pid));
2416 signal_vt_rel(scr_stat *scp)
2418 if (scp->smode.mode != VT_PROCESS)
2420 scp->status |= SWITCH_WAIT_REL;
2421 PROC_LOCK(scp->proc);
2422 psignal(scp->proc, scp->smode.relsig);
2423 PROC_UNLOCK(scp->proc);
2424 DPRINTF(5, ("sending relsig to %d\n", scp->pid));
2429 signal_vt_acq(scr_stat *scp)
2431 if (scp->smode.mode != VT_PROCESS)
2433 if (scp->sc->unit == sc_console_unit)
2434 cnavailable(sc_consptr, FALSE);
2435 scp->status |= SWITCH_WAIT_ACQ;
2436 PROC_LOCK(scp->proc);
2437 psignal(scp->proc, scp->smode.acqsig);
2438 PROC_UNLOCK(scp->proc);
2439 DPRINTF(5, ("sending acqsig to %d\n", scp->pid));
2444 finish_vt_rel(scr_stat *scp, int release, int *s)
2446 if (scp == scp->sc->old_scp && scp->status & SWITCH_WAIT_REL) {
2447 scp->status &= ~SWITCH_WAIT_REL;
2449 *s = do_switch_scr(scp->sc, *s);
2451 scp->sc->switch_in_progress = 0;
2458 finish_vt_acq(scr_stat *scp)
2460 if (scp == scp->sc->new_scp && scp->status & SWITCH_WAIT_ACQ) {
2461 scp->status &= ~SWITCH_WAIT_ACQ;
2462 scp->sc->switch_in_progress = 0;
2469 exchange_scr(sc_softc_t *sc)
2473 /* save the current state of video and keyboard */
2474 sc_move_cursor(sc->old_scp, sc->old_scp->xpos, sc->old_scp->ypos);
2475 if (!ISGRAPHSC(sc->old_scp))
2476 sc_remove_cursor_image(sc->old_scp);
2477 if (sc->old_scp->kbd_mode == K_XLATE)
2478 save_kbd_state(sc->old_scp);
2480 /* set up the video for the new screen */
2481 scp = sc->cur_scp = sc->new_scp;
2483 if (sc->old_scp->mode != scp->mode || ISUNKNOWNSC(sc->old_scp) || ISUNKNOWNSC(sc->new_scp))
2485 if (sc->old_scp->mode != scp->mode || ISUNKNOWNSC(sc->old_scp))
2490 sc_vtb_init(&scp->scr, VTB_FRAMEBUFFER, scp->xsize, scp->ysize,
2491 (void *)sc->adp->va_window, FALSE);
2493 scp->status |= MOUSE_HIDDEN;
2494 sc_move_cursor(scp, scp->xpos, scp->ypos);
2495 if (!ISGRAPHSC(scp))
2496 sc_set_cursor_image(scp);
2497 #ifndef SC_NO_PALETTE_LOADING
2498 if (ISGRAPHSC(sc->old_scp))
2499 load_palette(sc->adp, sc->palette);
2501 sc_set_border(scp, scp->border);
2503 /* set up the keyboard for the new screen */
2504 if (sc->old_scp->kbd_mode != scp->kbd_mode)
2505 kbd_ioctl(sc->kbd, KDSKBMODE, (caddr_t)&scp->kbd_mode);
2506 update_kbd_state(scp, scp->status, LOCK_MASK);
2512 sc_puts(scr_stat *scp, u_char *buf, int len)
2515 /* make screensaver happy */
2516 if (!sticky_splash && scp == scp->sc->cur_scp && !sc_saver_keyb_only)
2517 run_scrn_saver = FALSE;
2521 (*scp->tsw->te_puts)(scp, buf, len);
2523 if (scp->sc->delayed_next_scr)
2524 sc_switch_scr(scp->sc, scp->sc->delayed_next_scr - 1);
2528 sc_draw_cursor_image(scr_stat *scp)
2530 /* assert(scp == scp->sc->cur_scp); */
2531 SC_VIDEO_LOCK(scp->sc);
2532 (*scp->rndr->draw_cursor)(scp, scp->cursor_pos,
2533 scp->curs_attr.flags & CONS_BLINK_CURSOR, TRUE,
2534 sc_inside_cutmark(scp, scp->cursor_pos));
2535 scp->cursor_oldpos = scp->cursor_pos;
2536 SC_VIDEO_UNLOCK(scp->sc);
2540 sc_remove_cursor_image(scr_stat *scp)
2542 /* assert(scp == scp->sc->cur_scp); */
2543 SC_VIDEO_LOCK(scp->sc);
2544 (*scp->rndr->draw_cursor)(scp, scp->cursor_oldpos,
2545 scp->curs_attr.flags & CONS_BLINK_CURSOR, FALSE,
2546 sc_inside_cutmark(scp, scp->cursor_oldpos));
2547 SC_VIDEO_UNLOCK(scp->sc);
2551 update_cursor_image(scr_stat *scp)
2553 /* assert(scp == scp->sc->cur_scp); */
2554 sc_remove_cursor_image(scp);
2555 sc_set_cursor_image(scp);
2556 sc_draw_cursor_image(scp);
2560 sc_set_cursor_image(scr_stat *scp)
2562 scp->curs_attr.flags = scp->curr_curs_attr.flags;
2563 if (scp->curs_attr.flags & CONS_HIDDEN_CURSOR) {
2564 /* hidden cursor is internally represented as zero-height underline */
2565 scp->curs_attr.flags = CONS_CHAR_CURSOR;
2566 scp->curs_attr.base = scp->curs_attr.height = 0;
2567 } else if (scp->curs_attr.flags & CONS_CHAR_CURSOR) {
2568 scp->curs_attr.base = imin(scp->curr_curs_attr.base,
2569 scp->font_size - 1);
2570 scp->curs_attr.height = imin(scp->curr_curs_attr.height,
2571 scp->font_size - scp->curs_attr.base);
2572 } else { /* block cursor */
2573 scp->curs_attr.base = 0;
2574 scp->curs_attr.height = scp->font_size;
2577 /* assert(scp == scp->sc->cur_scp); */
2578 SC_VIDEO_LOCK(scp->sc);
2579 (*scp->rndr->set_cursor)(scp, scp->curs_attr.base, scp->curs_attr.height,
2580 scp->curs_attr.flags & CONS_BLINK_CURSOR);
2581 SC_VIDEO_UNLOCK(scp->sc);
2585 change_cursor_shape(scr_stat *scp, int flags, int base, int height)
2587 if ((scp == scp->sc->cur_scp) && !ISGRAPHSC(scp))
2588 sc_remove_cursor_image(scp);
2591 scp->curr_curs_attr.base = base;
2593 scp->curr_curs_attr.height = height;
2594 if (flags & CONS_RESET_CURSOR)
2595 scp->curr_curs_attr = scp->dflt_curs_attr;
2597 scp->curr_curs_attr.flags = flags & CONS_CURSOR_ATTRS;
2599 if ((scp == scp->sc->cur_scp) && !ISGRAPHSC(scp)) {
2600 sc_set_cursor_image(scp);
2601 sc_draw_cursor_image(scp);
2606 sc_change_cursor_shape(scr_stat *scp, int flags, int base, int height)
2614 if ((flags != -1) && (flags & CONS_LOCAL_CURSOR)) {
2615 /* local (per vty) change */
2616 change_cursor_shape(scp, flags, base, height);
2624 sc->curs_attr.base = base;
2626 sc->curs_attr.height = height;
2628 if (flags & CONS_RESET_CURSOR)
2629 sc->curs_attr = sc->dflt_curs_attr;
2631 sc->curs_attr.flags = flags & CONS_CURSOR_ATTRS;
2634 for (i = sc->first_vty; i < sc->first_vty + sc->vtys; ++i) {
2635 if ((dev = SC_DEV(sc, i)) == NULL)
2637 if ((scp = sc_get_stat(dev)) == NULL)
2639 scp->dflt_curs_attr = sc->curs_attr;
2640 change_cursor_shape(scp, CONS_RESET_CURSOR, -1, -1);
2646 scinit(int unit, int flags)
2650 * When syscons is being initialized as the kernel console, malloc()
2651 * is not yet functional, because various kernel structures has not been
2652 * fully initialized yet. Therefore, we need to declare the following
2653 * static buffers for the console. This is less than ideal,
2654 * but is necessry evil for the time being. XXX
2657 static u_short sc_buffer[ROW*COL*2];/* XXX */
2659 static u_short sc_buffer[ROW*COL]; /* XXX */
2661 #ifndef SC_NO_FONT_LOADING
2662 static u_char font_8[256*8];
2663 static u_char font_14[256*14];
2664 static u_char font_16[256*16];
2669 video_adapter_t *adp;
2674 /* one time initialization */
2675 if (init_done == COLD)
2676 sc_get_bios_values(&bios_value);
2680 * Allocate resources. Even if we are being called for the second
2681 * time, we must allocate them again, because they might have
2684 sc = sc_get_softc(unit, flags & SC_KERNEL_CONSOLE);
2685 if ((sc->flags & SC_INIT_DONE) == 0)
2686 SC_VIDEO_LOCKINIT(sc);
2689 if (sc->adapter >= 0) {
2690 vid_release(sc->adp, (void *)&sc->adapter);
2694 if (sc->keyboard >= 0) {
2695 DPRINTF(5, ("sc%d: releasing kbd%d\n", unit, sc->keyboard));
2696 i = kbd_release(sc->kbd, (void *)&sc->keyboard);
2697 DPRINTF(5, ("sc%d: kbd_release returned %d\n", unit, i));
2698 if (sc->kbd != NULL) {
2699 DPRINTF(5, ("sc%d: kbd != NULL!, index:%d, unit:%d, flags:0x%x\n",
2700 unit, sc->kbd->kb_index, sc->kbd->kb_unit, sc->kbd->kb_flags));
2704 sc->adapter = vid_allocate("*", unit, (void *)&sc->adapter);
2705 sc->adp = vid_get_adapter(sc->adapter);
2706 /* assert((sc->adapter >= 0) && (sc->adp != NULL)) */
2708 sc->keyboard = sc_allocate_keyboard(sc, unit);
2709 DPRINTF(1, ("sc%d: keyboard %d\n", unit, sc->keyboard));
2711 sc->kbd = kbd_get_keyboard(sc->keyboard);
2712 if (sc->kbd != NULL) {
2713 DPRINTF(1, ("sc%d: kbd index:%d, unit:%d, flags:0x%x\n",
2714 unit, sc->kbd->kb_index, sc->kbd->kb_unit, sc->kbd->kb_flags));
2717 if (!(sc->flags & SC_INIT_DONE) || (adp != sc->adp)) {
2719 sc->initial_mode = sc->adp->va_initial_mode;
2721 #ifndef SC_NO_FONT_LOADING
2722 if (flags & SC_KERNEL_CONSOLE) {
2723 sc->font_8 = font_8;
2724 sc->font_14 = font_14;
2725 sc->font_16 = font_16;
2726 } else if (sc->font_8 == NULL) {
2727 /* assert(sc_malloc) */
2728 sc->font_8 = malloc(sizeof(font_8), M_DEVBUF, M_WAITOK);
2729 sc->font_14 = malloc(sizeof(font_14), M_DEVBUF, M_WAITOK);
2730 sc->font_16 = malloc(sizeof(font_16), M_DEVBUF, M_WAITOK);
2734 /* extract the hardware cursor location and hide the cursor for now */
2735 (*vidsw[sc->adapter]->read_hw_cursor)(sc->adp, &col, &row);
2736 (*vidsw[sc->adapter]->set_hw_cursor)(sc->adp, -1, -1);
2738 /* set up the first console */
2739 sc->first_vty = unit*MAXCONS;
2740 sc->vtys = MAXCONS; /* XXX: should be configurable */
2741 if (flags & SC_KERNEL_CONSOLE) {
2743 * Set up devs structure but don't use it yet, calling make_dev()
2744 * might panic kernel. Wait for sc_attach_unit() to actually
2745 * create the devices.
2747 sc->dev = main_devs;
2748 scp = &main_console;
2749 init_scp(sc, sc->first_vty, scp);
2750 sc_vtb_init(&scp->vtb, VTB_MEMORY, scp->xsize, scp->ysize,
2751 (void *)sc_buffer, FALSE);
2752 if (sc_init_emulator(scp, SC_DFLT_TERM))
2753 sc_init_emulator(scp, "*");
2754 (*scp->tsw->te_default_attr)(scp,
2755 kernel_default.std_color,
2756 kernel_default.rev_color);
2758 /* assert(sc_malloc) */
2759 sc->dev = malloc(sizeof(struct cdev *)*sc->vtys, M_DEVBUF, M_WAITOK|M_ZERO);
2760 sc->dev[0] = make_dev(&sc_cdevsw, unit * MAXCONS,
2761 UID_ROOT, GID_WHEEL, 0600, "ttyv%r", unit * MAXCONS);
2762 sc_alloc_tty(sc->dev[0]);
2763 scp = alloc_scp(sc, sc->first_vty);
2764 SC_STAT(sc->dev[0]) = scp;
2769 /* copy screen to temporary buffer */
2770 sc_vtb_init(&scp->scr, VTB_FRAMEBUFFER, scp->xsize, scp->ysize,
2771 (void *)scp->sc->adp->va_window, FALSE);
2773 sc_vtb_copy(&scp->scr, 0, &scp->vtb, 0, scp->xsize*scp->ysize);
2776 /* move cursors to the initial positions */
2777 if (col >= scp->xsize)
2779 if (row >= scp->ysize)
2780 row = scp->ysize - 1;
2783 scp->cursor_pos = scp->cursor_oldpos = row*scp->xsize + col;
2785 if (bios_value.cursor_end < scp->font_size)
2786 sc->dflt_curs_attr.base = scp->font_size -
2787 bios_value.cursor_end - 1;
2789 sc->dflt_curs_attr.base = 0;
2790 i = bios_value.cursor_end - bios_value.cursor_start + 1;
2791 sc->dflt_curs_attr.height = imin(i, scp->font_size);
2792 sc->dflt_curs_attr.flags = 0;
2793 sc->curs_attr = sc->dflt_curs_attr;
2794 scp->curr_curs_attr = scp->dflt_curs_attr = sc->curs_attr;
2796 #ifndef SC_NO_SYSMOUSE
2797 sc_mouse_move(scp, scp->xpixel/2, scp->ypixel/2);
2799 if (!ISGRAPHSC(scp)) {
2800 sc_set_cursor_image(scp);
2801 sc_draw_cursor_image(scp);
2804 /* save font and palette */
2805 #ifndef SC_NO_FONT_LOADING
2806 sc->fonts_loaded = 0;
2807 if (ISFONTAVAIL(sc->adp->va_flags)) {
2809 bcopy(dflt_font_8, sc->font_8, sizeof(dflt_font_8));
2810 bcopy(dflt_font_14, sc->font_14, sizeof(dflt_font_14));
2811 bcopy(dflt_font_16, sc->font_16, sizeof(dflt_font_16));
2812 sc->fonts_loaded = FONT_16 | FONT_14 | FONT_8;
2813 if (scp->font_size < 14) {
2814 sc_load_font(scp, 0, 8, 8, sc->font_8, 0, 256);
2815 } else if (scp->font_size >= 16) {
2816 sc_load_font(scp, 0, 16, 8, sc->font_16, 0, 256);
2818 sc_load_font(scp, 0, 14, 8, sc->font_14, 0, 256);
2820 #else /* !SC_DFLT_FONT */
2821 if (scp->font_size < 14) {
2822 sc_save_font(scp, 0, 8, 8, sc->font_8, 0, 256);
2823 sc->fonts_loaded = FONT_8;
2824 } else if (scp->font_size >= 16) {
2825 sc_save_font(scp, 0, 16, 8, sc->font_16, 0, 256);
2826 sc->fonts_loaded = FONT_16;
2828 sc_save_font(scp, 0, 14, 8, sc->font_14, 0, 256);
2829 sc->fonts_loaded = FONT_14;
2831 #endif /* SC_DFLT_FONT */
2832 /* FONT KLUDGE: always use the font page #0. XXX */
2833 sc_show_font(scp, 0);
2835 #endif /* !SC_NO_FONT_LOADING */
2837 #ifndef SC_NO_PALETTE_LOADING
2838 save_palette(sc->adp, sc->palette);
2842 if (!(sc->flags & SC_SPLASH_SCRN)) {
2843 /* we are ready to put up the splash image! */
2844 splash_init(sc->adp, scsplash_callback, sc);
2845 sc->flags |= SC_SPLASH_SCRN;
2850 /* the rest is not necessary, if we have done it once */
2851 if (sc->flags & SC_INIT_DONE)
2854 /* initialize mapscrn arrays to a one to one map */
2855 for (i = 0; i < sizeof(sc->scr_map); i++)
2856 sc->scr_map[i] = sc->scr_rmap[i] = i;
2858 sc->scr_map[0x5c] = (u_char)0xfc; /* for backslash */
2861 sc->flags |= SC_INIT_DONE;
2865 scterm(int unit, int flags)
2870 sc = sc_get_softc(unit, flags & SC_KERNEL_CONSOLE);
2872 return; /* shouldn't happen */
2875 /* this console is no longer available for the splash screen */
2876 if (sc->flags & SC_SPLASH_SCRN) {
2877 splash_term(sc->adp);
2878 sc->flags &= ~SC_SPLASH_SCRN;
2883 /* move the hardware cursor to the upper-left corner */
2884 (*vidsw[sc->adapter]->set_hw_cursor)(sc->adp, 0, 0);
2887 /* release the keyboard and the video card */
2888 if (sc->keyboard >= 0)
2889 kbd_release(sc->kbd, &sc->keyboard);
2890 if (sc->adapter >= 0)
2891 vid_release(sc->adp, &sc->adapter);
2893 /* stop the terminal emulator, if any */
2894 scp = sc_get_stat(sc->dev[0]);
2896 (*scp->tsw->te_term)(scp, &scp->ts);
2897 if (scp->ts != NULL)
2898 free(scp->ts, M_DEVBUF);
2900 /* clear the structure */
2901 if (!(flags & SC_KERNEL_CONSOLE)) {
2902 /* XXX: We need delete_dev() for this */
2903 free(sc->dev, M_DEVBUF);
2905 /* XXX: We need a ttyunregister for this */
2906 free(sc->tty, M_DEVBUF);
2908 #ifndef SC_NO_FONT_LOADING
2909 free(sc->font_8, M_DEVBUF);
2910 free(sc->font_14, M_DEVBUF);
2911 free(sc->font_16, M_DEVBUF);
2913 /* XXX vtb, history */
2915 bzero(sc, sizeof(*sc));
2921 scshutdown(void *arg, int howto)
2923 /* assert(sc_console != NULL) */
2925 sc_touch_scrn_saver();
2926 if (!cold && sc_console
2927 && sc_console->sc->cur_scp->smode.mode == VT_AUTO
2928 && sc_console->smode.mode == VT_AUTO)
2929 sc_switch_scr(sc_console->sc, sc_console->index);
2930 shutdown_in_progress = TRUE;
2934 sc_clean_up(scr_stat *scp)
2940 if (scp->sc->flags & SC_SCRN_BLANKED) {
2941 sc_touch_scrn_saver();
2943 if ((error = wait_scrn_saver_stop(scp->sc)))
2947 scp->status |= MOUSE_HIDDEN;
2948 sc_remove_mouse_image(scp);
2949 sc_remove_cutmarking(scp);
2954 sc_alloc_scr_buffer(scr_stat *scp, int wait, int discard)
2960 sc_vtb_init(&new, VTB_MEMORY, scp->xsize, scp->ysize, NULL, wait);
2961 if (!discard && (old.vtb_flags & VTB_VALID)) {
2962 /* retain the current cursor position and buffer contants */
2963 scp->cursor_oldpos = scp->cursor_pos;
2965 * This works only if the old buffer has the same size as or larger
2966 * than the new one. XXX
2968 sc_vtb_copy(&old, 0, &new, 0, scp->xsize*scp->ysize);
2972 sc_vtb_destroy(&old);
2975 #ifndef SC_NO_SYSMOUSE
2976 /* move the mouse cursor at the center of the screen */
2977 sc_mouse_move(scp, scp->xpixel / 2, scp->ypixel / 2);
2982 *alloc_scp(sc_softc_t *sc, int vty)
2986 /* assert(sc_malloc) */
2988 scp = (scr_stat *)malloc(sizeof(scr_stat), M_DEVBUF, M_WAITOK);
2989 init_scp(sc, vty, scp);
2991 sc_alloc_scr_buffer(scp, TRUE, TRUE);
2992 if (sc_init_emulator(scp, SC_DFLT_TERM))
2993 sc_init_emulator(scp, "*");
2995 #ifndef SC_NO_CUTPASTE
2996 sc_alloc_cut_buffer(scp, TRUE);
2999 #ifndef SC_NO_HISTORY
3000 sc_alloc_history_buffer(scp, 0, 0, TRUE);
3007 init_scp(sc_softc_t *sc, int vty, scr_stat *scp)
3011 bzero(scp, sizeof(*scp));
3016 scp->mode = sc->initial_mode;
3017 (*vidsw[sc->adapter]->get_info)(sc->adp, scp->mode, &info);
3018 if (info.vi_flags & V_INFO_GRAPHICS) {
3019 scp->status |= GRAPHICS_MODE;
3020 scp->xpixel = info.vi_width;
3021 scp->ypixel = info.vi_height;
3022 scp->xsize = info.vi_width/info.vi_cwidth;
3023 scp->ysize = info.vi_height/info.vi_cheight;
3027 scp->xsize = info.vi_width;
3028 scp->ysize = info.vi_height;
3029 scp->xpixel = scp->xsize*info.vi_cwidth;
3030 scp->ypixel = scp->ysize*info.vi_cheight;
3031 scp->font_size = info.vi_cheight;
3032 scp->font_width = info.vi_cwidth;
3033 if (info.vi_cheight < 14) {
3034 #ifndef SC_NO_FONT_LOADING
3035 scp->font = sc->font_8;
3039 } else if (info.vi_cheight >= 16) {
3040 #ifndef SC_NO_FONT_LOADING
3041 scp->font = sc->font_16;
3046 #ifndef SC_NO_FONT_LOADING
3047 scp->font = sc->font_14;
3053 sc_vtb_init(&scp->vtb, VTB_MEMORY, 0, 0, NULL, FALSE);
3055 sc_vtb_init(&scp->scr, VTB_FRAMEBUFFER, 0, 0, NULL, FALSE);
3057 scp->xoff = scp->yoff = 0;
3058 scp->xpos = scp->ypos = 0;
3059 scp->start = scp->xsize * scp->ysize - 1;
3064 scp->border = (SC_NORM_ATTR >> 4) & 0x0f;
3065 scp->curr_curs_attr = scp->dflt_curs_attr = sc->curs_attr;
3066 scp->mouse_cut_start = scp->xsize*scp->ysize;
3067 scp->mouse_cut_end = -1;
3068 scp->mouse_signal = 0;
3070 scp->mouse_proc = NULL;
3071 scp->kbd_mode = K_XLATE;
3072 scp->bell_pitch = bios_value.bell_pitch;
3073 scp->bell_duration = BELL_DURATION;
3074 scp->status |= (bios_value.shift_state & NLKED);
3075 scp->status |= CURSOR_ENABLED | MOUSE_HIDDEN;
3078 scp->smode.mode = VT_AUTO;
3079 scp->history = NULL;
3080 scp->history_pos = 0;
3081 scp->history_size = 0;
3085 sc_init_emulator(scr_stat *scp, char *name)
3092 if (name == NULL) /* if no name is given, use the current emulator */
3094 else /* ...otherwise find the named emulator */
3095 sw = sc_term_match(name);
3100 if (strcmp(sw->te_renderer, "*") != 0) {
3101 rndr = sc_render_match(scp, sw->te_renderer,
3102 scp->status & (GRAPHICS_MODE | PIXEL_MODE));
3105 rndr = sc_render_match(scp, scp->sc->adp->va_name,
3106 scp->status & (GRAPHICS_MODE | PIXEL_MODE));
3111 if (sw == scp->tsw) {
3112 error = (*sw->te_init)(scp, &scp->ts, SC_TE_WARM_INIT);
3114 scp->rndr->init(scp);
3115 sc_clear_screen(scp);
3116 /* assert(error == 0); */
3120 if (sc_malloc && (sw->te_size > 0))
3121 p = malloc(sw->te_size, M_DEVBUF, M_NOWAIT);
3124 error = (*sw->te_init)(scp, &p, SC_TE_COLD_INIT);
3129 (*scp->tsw->te_term)(scp, &scp->ts);
3130 if (scp->ts != NULL)
3131 free(scp->ts, M_DEVBUF);
3135 scp->rndr->init(scp);
3138 (*sw->te_default_attr)(scp, user_default.std_color, user_default.rev_color);
3139 sc_clear_screen(scp);
3145 * scgetc(flags) - get character from keyboard.
3146 * If flags & SCGETC_CN, then avoid harmful side effects.
3147 * If flags & SCGETC_NONBLOCK, then wait until a key is pressed, else
3148 * return NOKEY if there is nothing there.
3151 scgetc(sc_softc_t *sc, u_int flags)
3154 #ifndef SC_NO_HISTORY
3162 if (sc->kbd == NULL)
3167 /* I don't like this, but... XXX */
3168 if (flags & SCGETC_CN)
3169 sccnupdate(sc->cur_scp);
3172 /* first see if there is something in the keyboard port */
3174 c = kbd_read_char(sc->kbd, !(flags & SCGETC_NONBLOCK));
3176 if (!(flags & SCGETC_CN))
3177 sc_bell(scp, bios_value.bell_pitch, BELL_DURATION);
3178 } else if (c == NOKEY)
3184 /* make screensaver happy */
3186 sc_touch_scrn_saver();
3188 if (!(flags & SCGETC_CN))
3189 random_harvest(&c, sizeof(c), 1, 0, RANDOM_KEYBOARD);
3191 if (scp->kbd_mode != K_XLATE)
3194 /* if scroll-lock pressed allow history browsing */
3195 if (!ISGRAPHSC(scp) && scp->history && scp->status & SLKED) {
3197 scp->status &= ~CURSOR_ENABLED;
3198 sc_remove_cursor_image(scp);
3200 #ifndef SC_NO_HISTORY
3201 if (!(scp->status & BUFFER_SAVED)) {
3202 scp->status |= BUFFER_SAVED;
3206 /* FIXME: key codes */
3207 case SPCLKEY | FKEY | F(49): /* home key */
3208 sc_remove_cutmarking(scp);
3212 case SPCLKEY | FKEY | F(57): /* end key */
3213 sc_remove_cutmarking(scp);
3217 case SPCLKEY | FKEY | F(50): /* up arrow key */
3218 sc_remove_cutmarking(scp);
3219 if (sc_hist_up_line(scp))
3220 if (!(flags & SCGETC_CN))
3221 sc_bell(scp, bios_value.bell_pitch, BELL_DURATION);
3224 case SPCLKEY | FKEY | F(58): /* down arrow key */
3225 sc_remove_cutmarking(scp);
3226 if (sc_hist_down_line(scp))
3227 if (!(flags & SCGETC_CN))
3228 sc_bell(scp, bios_value.bell_pitch, BELL_DURATION);
3231 case SPCLKEY | FKEY | F(51): /* page up key */
3232 sc_remove_cutmarking(scp);
3233 for (i=0; i<scp->ysize; i++)
3234 if (sc_hist_up_line(scp)) {
3235 if (!(flags & SCGETC_CN))
3236 sc_bell(scp, bios_value.bell_pitch, BELL_DURATION);
3241 case SPCLKEY | FKEY | F(59): /* page down key */
3242 sc_remove_cutmarking(scp);
3243 for (i=0; i<scp->ysize; i++)
3244 if (sc_hist_down_line(scp)) {
3245 if (!(flags & SCGETC_CN))
3246 sc_bell(scp, bios_value.bell_pitch, BELL_DURATION);
3251 #endif /* SC_NO_HISTORY */
3255 * Process and consume special keys here. Return a plain char code
3256 * or a char code with the META flag or a function key code.
3260 /* goto next_code */
3265 switch (KEYCHAR(c)) {
3267 case NLK: case CLK: case ALK:
3270 kbd_ioctl(sc->kbd, KDGKBSTATE, (caddr_t)&f);
3272 scp->status |= SLKED;
3274 if (scp->status & SLKED) {
3275 scp->status &= ~SLKED;
3276 #ifndef SC_NO_HISTORY
3277 if (scp->status & BUFFER_SAVED) {
3278 if (!sc_hist_restore(scp))
3279 sc_remove_cutmarking(scp);
3280 scp->status &= ~BUFFER_SAVED;
3281 scp->status |= CURSOR_ENABLED;
3282 sc_draw_cursor_image(scp);
3284 tp = VIRTUAL_TTY(sc, scp->index);
3293 #ifndef SC_NO_CUTPASTE
3294 sc_mouse_paste(scp);
3298 /* NON-LOCKING KEYS */
3300 case LSH: case RSH: case LCTR: case RCTR:
3301 case LALT: case RALT: case ASH: case META:
3305 if (!(sc->flags & SC_SCRN_BLANKED))
3311 /* force activatation/deactivation of the screen saver */
3312 if (!(sc->flags & SC_SCRN_BLANKED)) {
3313 run_scrn_saver = TRUE;
3314 sc->scrn_time_stamp -= scrn_blank_time;
3318 * While devices are being probed, the screen saver need
3319 * to be invoked explictly. XXX
3321 if (sc->flags & SC_SCRN_BLANKED) {
3322 scsplash_stick(FALSE);
3323 stop_scrn_saver(sc, current_saver);
3325 if (!ISGRAPHSC(scp)) {
3326 scsplash_stick(TRUE);
3327 (*current_saver)(sc, TRUE);
3331 #endif /* DEV_SPLASH */
3335 #ifndef SC_DISABLE_REBOOT
3342 #ifndef SC_DISABLE_REBOOT
3344 shutdown_nice(RB_HALT);
3349 #ifndef SC_DISABLE_REBOOT
3351 shutdown_nice(RB_HALT|RB_POWEROFF);
3356 power_pm_suspend(POWER_SLEEP_STATE_SUSPEND);
3359 power_pm_suspend(POWER_SLEEP_STATE_STANDBY);
3363 #ifndef SC_DISABLE_KDBKEY
3365 kdb_enter("manual escape to debugger");
3370 if (enable_panic_key)
3371 panic("Forced by the panic key");
3375 this_scr = scp->index;
3376 for (i = (this_scr - sc->first_vty + 1)%sc->vtys;
3377 sc->first_vty + i != this_scr;
3378 i = (i + 1)%sc->vtys) {
3379 struct tty *tp = VIRTUAL_TTY(sc, sc->first_vty + i);
3380 if (ISTTYOPEN(tp)) {
3381 sc_switch_scr(scp->sc, sc->first_vty + i);
3388 this_scr = scp->index;
3389 for (i = (this_scr - sc->first_vty + sc->vtys - 1)%sc->vtys;
3390 sc->first_vty + i != this_scr;
3391 i = (i + sc->vtys - 1)%sc->vtys) {
3392 struct tty *tp = VIRTUAL_TTY(sc, sc->first_vty + i);
3393 if (ISTTYOPEN(tp)) {
3394 sc_switch_scr(scp->sc, sc->first_vty + i);
3401 if (KEYCHAR(c) >= F_SCR && KEYCHAR(c) <= L_SCR) {
3402 sc_switch_scr(scp->sc, sc->first_vty + KEYCHAR(c) - F_SCR);
3405 /* assert(c & FKEY) */
3406 if (!(sc->flags & SC_SCRN_BLANKED))
3410 /* goto next_code */
3412 /* regular keys (maybe MKEY is set) */
3413 if (!(sc->flags & SC_SCRN_BLANKED))
3422 scmmap(struct cdev *dev, vm_offset_t offset, vm_paddr_t *paddr, int nprot)
3426 scp = sc_get_stat(dev);
3427 if (scp != scp->sc->cur_scp)
3429 return (*vidsw[scp->sc->adapter]->mmap)(scp->sc->adp, offset, paddr, nprot);
3433 save_kbd_state(scr_stat *scp)
3438 error = kbd_ioctl(scp->sc->kbd, KDGKBSTATE, (caddr_t)&state);
3439 if (error == ENOIOCTL)
3442 scp->status &= ~LOCK_MASK;
3443 scp->status |= state;
3449 update_kbd_state(scr_stat *scp, int new_bits, int mask)
3454 if (mask != LOCK_MASK) {
3455 error = kbd_ioctl(scp->sc->kbd, KDGKBSTATE, (caddr_t)&state);
3456 if (error == ENOIOCTL)
3461 state |= new_bits & mask;
3463 state = new_bits & LOCK_MASK;
3465 error = kbd_ioctl(scp->sc->kbd, KDSKBSTATE, (caddr_t)&state);
3466 if (error == ENOIOCTL)
3472 update_kbd_leds(scr_stat *scp, int which)
3477 error = kbd_ioctl(scp->sc->kbd, KDSETLED, (caddr_t)&which);
3478 if (error == ENOIOCTL)
3484 set_mode(scr_stat *scp)
3488 /* reject unsupported mode */
3489 if ((*vidsw[scp->sc->adapter]->get_info)(scp->sc->adp, scp->mode, &info))
3492 /* if this vty is not currently showing, do nothing */
3493 if (scp != scp->sc->cur_scp)
3496 /* setup video hardware for the given mode */
3497 (*vidsw[scp->sc->adapter]->set_mode)(scp->sc->adp, scp->mode);
3498 scp->rndr->init(scp);
3500 sc_vtb_init(&scp->scr, VTB_FRAMEBUFFER, scp->xsize, scp->ysize,
3501 (void *)scp->sc->adp->va_window, FALSE);
3504 #ifndef SC_NO_FONT_LOADING
3505 /* load appropriate font */
3506 if (!(scp->status & GRAPHICS_MODE)) {
3507 if (!(scp->status & PIXEL_MODE) && ISFONTAVAIL(scp->sc->adp->va_flags)) {
3508 if (scp->font_size < 14) {
3509 if (scp->sc->fonts_loaded & FONT_8)
3510 sc_load_font(scp, 0, 8, 8, scp->sc->font_8, 0, 256);
3511 } else if (scp->font_size >= 16) {
3512 if (scp->sc->fonts_loaded & FONT_16)
3513 sc_load_font(scp, 0, 16, 8, scp->sc->font_16, 0, 256);
3515 if (scp->sc->fonts_loaded & FONT_14)
3516 sc_load_font(scp, 0, 14, 8, scp->sc->font_14, 0, 256);
3520 * This is an interim kludge to display correct font.
3521 * Always use the font page #0 on the video plane 2.
3522 * Somehow we cannot show the font in other font pages on
3523 * some video cards... XXX
3525 sc_show_font(scp, 0);
3529 #endif /* !SC_NO_FONT_LOADING */
3531 sc_set_border(scp, scp->border);
3532 sc_set_cursor_image(scp);
3538 sc_set_border(scr_stat *scp, int color)
3540 SC_VIDEO_LOCK(scp->sc);
3541 (*scp->rndr->draw_border)(scp, color);
3542 SC_VIDEO_UNLOCK(scp->sc);
3545 #ifndef SC_NO_FONT_LOADING
3547 sc_load_font(scr_stat *scp, int page, int size, int width, u_char *buf,
3548 int base, int count)
3553 sc->font_loading_in_progress = TRUE;
3554 (*vidsw[sc->adapter]->load_font)(sc->adp, page, size, width, buf, base,
3556 sc->font_loading_in_progress = FALSE;
3560 sc_save_font(scr_stat *scp, int page, int size, int width, u_char *buf,
3561 int base, int count)
3566 sc->font_loading_in_progress = TRUE;
3567 (*vidsw[sc->adapter]->save_font)(sc->adp, page, size, width, buf, base,
3569 sc->font_loading_in_progress = FALSE;
3573 sc_show_font(scr_stat *scp, int page)
3575 (*vidsw[scp->sc->adapter]->show_font)(scp->sc->adp, page);
3577 #endif /* !SC_NO_FONT_LOADING */
3580 sc_paste(scr_stat *scp, u_char *p, int count)
3585 tp = VIRTUAL_TTY(scp->sc, scp->sc->cur_scp->index);
3588 rmap = scp->sc->scr_rmap;
3589 for (; count > 0; --count)
3590 ttyld_rint(tp, rmap[*p++]);
3594 sc_bell(scr_stat *scp, int pitch, int duration)
3596 if (cold || shutdown_in_progress || !enable_bell)
3599 if (scp != scp->sc->cur_scp && (scp->sc->flags & SC_QUIET_BELL))
3602 if (scp->sc->flags & SC_VISUAL_BELL) {
3603 if (scp->sc->blink_in_progress)
3605 scp->sc->blink_in_progress = 3;
3606 if (scp != scp->sc->cur_scp)
3607 scp->sc->blink_in_progress += 2;
3608 blink_screen(scp->sc->cur_scp);
3609 } else if (duration != 0 && pitch != 0) {
3610 if (scp != scp->sc->cur_scp)
3612 sysbeep(pitch, duration);
3617 blink_screen(void *arg)
3619 scr_stat *scp = arg;
3622 if (ISGRAPHSC(scp) || (scp->sc->blink_in_progress <= 1)) {
3623 scp->sc->blink_in_progress = 0;
3625 tp = VIRTUAL_TTY(scp->sc, scp->index);
3628 if (scp->sc->delayed_next_scr)
3629 sc_switch_scr(scp->sc, scp->sc->delayed_next_scr - 1);
3632 (*scp->rndr->draw)(scp, 0, scp->xsize*scp->ysize,
3633 scp->sc->blink_in_progress & 1);
3634 scp->sc->blink_in_progress--;
3635 timeout(blink_screen, scp, hz / 10);
3640 * Until sc_attach_unit() gets called no dev structures will be available
3641 * to store the per-screen current status. This is the case when the
3642 * kernel is initially booting and needs access to its console. During
3643 * this early phase of booting the console's current status is kept in
3644 * one statically defined scr_stat structure, and any pointers to the
3645 * dev structures will be NULL.
3649 sc_get_stat(struct cdev *devptr)
3652 return (&main_console);
3653 return (SC_STAT(devptr));
3657 * Allocate active keyboard. Try to allocate "kbdmux" keyboard first, and,
3658 * if found, add all non-busy keyboards to "kbdmux". Otherwise look for
3663 sc_allocate_keyboard(sc_softc_t *sc, int unit)
3669 idx0 = kbd_allocate("kbdmux", -1, (void *)&sc->keyboard, sckbdevent, sc);
3671 k0 = kbd_get_keyboard(idx0);
3673 for (idx = kbd_find_keyboard2("*", -1, 0);
3675 idx = kbd_find_keyboard2("*", -1, idx + 1)) {
3676 k = kbd_get_keyboard(idx);
3678 if (idx == idx0 || KBD_IS_BUSY(k))
3681 bzero(&ki, sizeof(ki));
3682 strcpy(ki.kb_name, k->kb_name);
3683 ki.kb_unit = k->kb_unit;
3685 kbd_ioctl(k0, KBADDKBD, (caddr_t) &ki);
3688 idx0 = kbd_allocate("*", unit, (void *)&sc->keyboard, sckbdevent, sc);