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 VTY_WCHAN(sc, vty) (&SC_DEV(sc, vty))
164 #define VIRTUAL_TTY(sc, x) (SC_DEV((sc), (x)) != NULL ? \
165 SC_DEV((sc), (x))->si_tty : NULL)
166 #define ISTTYOPEN(tp) ((tp) && ((tp)->t_state & TS_ISOPEN))
171 static int sc_allocate_keyboard(sc_softc_t *sc, int unit);
172 static struct tty *sc_alloc_tty(struct cdev *dev);
173 static int scvidprobe(int unit, int flags, int cons);
174 static int sckbdprobe(int unit, int flags, int cons);
175 static void scmeminit(void *arg);
176 static int scdevtounit(struct cdev *dev);
177 static kbd_callback_func_t sckbdevent;
178 static int scparam(struct tty *tp, struct termios *t);
179 static void scstart(struct tty *tp);
180 static void scinit(int unit, int flags);
181 static scr_stat *sc_get_stat(struct cdev *devptr);
182 static void scterm(int unit, int flags);
183 static void scshutdown(void *arg, int howto);
184 static u_int scgetc(sc_softc_t *sc, u_int flags);
186 #define SCGETC_NONBLOCK 2
187 static int sccngetch(int flags);
188 static void sccnupdate(scr_stat *scp);
189 static scr_stat *alloc_scp(sc_softc_t *sc, int vty);
190 static void init_scp(sc_softc_t *sc, int vty, scr_stat *scp);
191 static timeout_t scrn_timer;
192 static int and_region(int *s1, int *e1, int s2, int e2);
193 static void scrn_update(scr_stat *scp, int show_cursor);
196 static int scsplash_callback(int event, void *arg);
197 static void scsplash_saver(sc_softc_t *sc, int show);
198 static int add_scrn_saver(void (*this_saver)(sc_softc_t *, int));
199 static int remove_scrn_saver(void (*this_saver)(sc_softc_t *, int));
200 static int set_scrn_saver_mode(scr_stat *scp, int mode, u_char *pal, int border);
201 static int restore_scrn_saver_mode(scr_stat *scp, int changemode);
202 static void stop_scrn_saver(sc_softc_t *sc, void (*saver)(sc_softc_t *, int));
203 static int wait_scrn_saver_stop(sc_softc_t *sc);
204 #define scsplash_stick(stick) (sticky_splash = (stick))
205 #else /* !DEV_SPLASH */
206 #define scsplash_stick(stick)
207 #endif /* DEV_SPLASH */
209 static int do_switch_scr(sc_softc_t *sc, int s);
210 static int vt_proc_alive(scr_stat *scp);
211 static int signal_vt_rel(scr_stat *scp);
212 static int signal_vt_acq(scr_stat *scp);
213 static int finish_vt_rel(scr_stat *scp, int release, int *s);
214 static int finish_vt_acq(scr_stat *scp);
215 static void exchange_scr(sc_softc_t *sc);
216 static void update_cursor_image(scr_stat *scp);
217 static void change_cursor_shape(scr_stat *scp, int flags, int base, int height);
218 static int save_kbd_state(scr_stat *scp);
219 static int update_kbd_state(scr_stat *scp, int state, int mask);
220 static int update_kbd_leds(scr_stat *scp, int which);
221 static timeout_t blink_screen;
223 static cn_probe_t sc_cnprobe;
224 static cn_init_t sc_cninit;
225 static cn_term_t sc_cnterm;
226 static cn_getc_t sc_cngetc;
227 static cn_putc_t sc_cnputc;
231 static d_open_t scopen;
232 static d_close_t scclose;
233 static d_read_t scread;
234 static d_ioctl_t scioctl;
235 static d_mmap_t scmmap;
237 static struct cdevsw sc_cdevsw = {
238 .d_version = D_VERSION,
245 .d_flags = D_TTY | D_NEEDGIANT,
249 sc_probe_unit(int unit, int flags)
251 if (!scvidprobe(unit, flags, FALSE)) {
253 printf("%s%d: no video adapter found.\n", SC_DRIVER_NAME, unit);
257 /* syscons will be attached even when there is no keyboard */
258 sckbdprobe(unit, flags, FALSE);
263 /* probe video adapters, return TRUE if found */
265 scvidprobe(int unit, int flags, int cons)
268 * Access the video adapter driver through the back door!
269 * Video adapter drivers need to be configured before syscons.
270 * However, when syscons is being probed as the low-level console,
271 * they have not been initialized yet. We force them to initialize
272 * themselves here. XXX
274 vid_configure(cons ? VIO_PROBE_ONLY : 0);
276 return (vid_find_adapter("*", unit) >= 0);
279 /* probe the keyboard, return TRUE if found */
281 sckbdprobe(int unit, int flags, int cons)
283 /* access the keyboard driver through the backdoor! */
284 kbd_configure(cons ? KB_CONF_PROBE_ONLY : 0);
286 return (kbd_find_keyboard("*", unit) >= 0);
290 *adapter_name(video_adapter_t *adp)
296 { KD_MONO, { "MDA", "MDA" } },
297 { KD_HERCULES, { "Hercules", "Hercules" } },
298 { KD_CGA, { "CGA", "CGA" } },
299 { KD_EGA, { "EGA", "EGA (mono)" } },
300 { KD_VGA, { "VGA", "VGA (mono)" } },
301 { KD_PC98, { "PC-98x1", "PC-98x1" } },
302 { KD_TGA, { "TGA", "TGA" } },
303 { -1, { "Unknown", "Unknown" } },
307 for (i = 0; names[i].type != -1; ++i)
308 if (names[i].type == adp->va_type)
310 return names[i].name[(adp->va_flags & V_ADP_COLOR) ? 0 : 1];
314 sc_alloc_tty(struct cdev *dev)
318 tp = dev->si_tty = ttyalloc();
319 ttyinitmode(tp, 1, 0);
320 tp->t_oproc = scstart;
321 tp->t_param = scparam;
322 tp->t_stop = nottystop;
328 sc_attach_unit(int unit, int flags)
338 flags &= ~SC_KERNEL_CONSOLE;
340 if (sc_console_unit == unit) {
342 * If this unit is being used as the system console, we need to
343 * adjust some variables and buffers before and after scinit().
345 /* assert(sc_console != NULL) */
346 flags |= SC_KERNEL_CONSOLE;
351 if (sc_console->tsw->te_size > 0) {
352 /* assert(sc_console->ts != NULL); */
353 kernel_console_ts = sc_console->ts;
354 sc_console->ts = malloc(sc_console->tsw->te_size,
356 bcopy(kernel_console_ts, sc_console->ts, sc_console->tsw->te_size);
357 (*sc_console->tsw->te_default_attr)(sc_console,
358 user_default.std_color,
359 user_default.rev_color);
365 sc = sc_get_softc(unit, flags & SC_KERNEL_CONSOLE);
367 scp = sc_get_stat(sc->dev[0]);
368 if (sc_console == NULL) /* sc_console_unit < 0 */
372 if ((sc->config & SC_VESA800X600)
373 && ((*vidsw[sc->adapter]->get_info)(sc->adp, M_VESA_800x600, &info) == 0)) {
375 if (sc->flags & SC_SPLASH_SCRN)
376 splash_term(sc->adp);
378 sc_set_graphics_mode(scp, NULL, M_VESA_800x600);
379 sc_set_pixel_mode(scp, NULL, COL, ROW, 16, 8);
380 sc->initial_mode = M_VESA_800x600;
382 /* put up the splash again! */
383 if (sc->flags & SC_SPLASH_SCRN)
384 splash_init(sc->adp, scsplash_callback, sc);
387 #endif /* SC_PIXEL_MODE */
389 /* initialize cursor */
391 update_cursor_image(scp);
393 /* get screen update going */
396 /* set up the keyboard */
397 kbd_ioctl(sc->kbd, KDSKBMODE, (caddr_t)&scp->kbd_mode);
398 update_kbd_state(scp, scp->status, LOCK_MASK);
400 printf("%s%d: %s <%d virtual consoles, flags=0x%x>\n",
401 SC_DRIVER_NAME, unit, adapter_name(sc->adp), sc->vtys, sc->config);
403 printf("%s%d:", SC_DRIVER_NAME, unit);
404 if (sc->adapter >= 0)
405 printf(" fb%d", sc->adapter);
406 if (sc->keyboard >= 0)
407 printf(", kbd%d", sc->keyboard);
409 printf(", terminal emulator: %s (%s)",
410 scp->tsw->te_name, scp->tsw->te_desc);
414 /* register a shutdown callback for the kernel console */
415 if (sc_console_unit == unit)
416 EVENTHANDLER_REGISTER(shutdown_pre_sync, scshutdown,
417 (void *)(uintptr_t)unit, SHUTDOWN_PRI_DEFAULT);
419 for (vc = 0; vc < sc->vtys; vc++) {
420 if (sc->dev[vc] == NULL) {
421 sc->dev[vc] = make_dev(&sc_cdevsw, vc + unit * MAXCONS,
422 UID_ROOT, GID_WHEEL, 0600, "ttyv%r", vc + unit * MAXCONS);
423 sc_alloc_tty(sc->dev[vc]);
424 if (vc == 0 && sc->dev == main_devs)
425 SC_STAT(sc->dev[0]) = &main_console;
428 * The first vty already has struct tty and scr_stat initialized
429 * in scinit(). The other vtys will have these structs when
434 dev = make_dev(&sc_cdevsw, SC_CONSOLECTL,
435 UID_ROOT, GID_WHEEL, 0600, "consolectl");
436 sc_console_tty = sc_alloc_tty(dev);
437 ttyconsolemode(sc_console_tty, 0);
438 SC_STAT(dev) = sc_console;
451 * As soon as malloc() becomes functional, we had better allocate
452 * various buffers for the kernel console.
455 if (sc_console_unit < 0) /* sc_console == NULL */
458 /* copy the temporary buffer to the final buffer */
459 sc_alloc_scr_buffer(sc_console, FALSE, FALSE);
461 #ifndef SC_NO_CUTPASTE
462 sc_alloc_cut_buffer(sc_console, FALSE);
465 #ifndef SC_NO_HISTORY
466 /* initialize history buffer & pointers */
467 sc_alloc_history_buffer(sc_console, 0, 0, FALSE);
472 SYSINIT(sc_mem, SI_SUB_KMEM, SI_ORDER_ANY, scmeminit, NULL);
475 scdevtounit(struct cdev *dev)
477 int vty = SC_VTY(dev);
479 if (vty == SC_CONSOLECTL)
480 return ((sc_console != NULL) ? sc_console->sc->unit : -1);
481 else if ((vty < 0) || (vty >= MAXCONS*sc_max_unit()))
488 scopen(struct cdev *dev, int flag, int mode, struct thread *td)
490 int unit = scdevtounit(dev);
499 DPRINTF(5, ("scopen: dev:%s, unit:%d, vty:%d\n",
500 devtoname(dev), unit, SC_VTY(dev)));
503 sc = sc_get_softc(unit, (sc_console_unit == unit) ? SC_KERNEL_CONSOLE : 0);
507 if (!ISTTYOPEN(tp)) {
508 tp->t_termios = tp->t_init_in;
509 /* Use the current setting of the <-- key as default VERASE. */
510 /* If the Delete key is preferable, an stty is necessary */
512 if (sc->kbd != NULL) {
513 key.keynum = KEYCODE_BS;
514 kbd_ioctl(sc->kbd, GIO_KEYMAPENT, (caddr_t)&key);
515 tp->t_cc[VERASE] = key.key.map[0];
518 scparam(tp, &tp->t_termios);
522 if (tp->t_state & TS_XCLUDE && priv_check(td, PRIV_TTY_EXCLUSIVE))
525 error = ttyld_open(tp, dev);
527 scp = sc_get_stat(dev);
529 scp = SC_STAT(dev) = alloc_scp(sc, SC_VTY(dev));
531 sc_set_pixel_mode(scp, NULL, COL, ROW, 16, 8);
533 if (!tp->t_winsize.ws_col && !tp->t_winsize.ws_row) {
534 tp->t_winsize.ws_col = scp->xsize;
535 tp->t_winsize.ws_row = scp->ysize;
542 scclose(struct cdev *dev, int flag, int mode, struct thread *td)
544 struct tty *tp = dev->si_tty;
548 if (SC_VTY(dev) != SC_CONSOLECTL) {
549 scp = sc_get_stat(tp->t_dev);
550 /* were we in the middle of the VT switching process? */
551 DPRINTF(5, ("sc%d: scclose(), ", scp->sc->unit));
553 if ((scp == scp->sc->cur_scp) && (scp->sc->unit == sc_console_unit))
554 cnavailable(sc_consptr, TRUE);
555 if (finish_vt_rel(scp, TRUE, &s) == 0) /* force release */
556 DPRINTF(5, ("reset WAIT_REL, "));
557 if (finish_vt_acq(scp) == 0) /* force acknowledge */
558 DPRINTF(5, ("reset WAIT_ACQ, "));
560 if (scp == &main_console) {
563 scp->smode.mode = VT_AUTO;
566 sc_vtb_destroy(&scp->vtb);
568 sc_vtb_destroy(&scp->scr);
570 sc_free_history_buffer(scp, scp->ysize);
577 scp->smode.mode = VT_AUTO;
579 scp->kbd_mode = K_XLATE;
580 if (scp == scp->sc->cur_scp)
581 kbd_ioctl(scp->sc->kbd, KDSKBMODE, (caddr_t)&scp->kbd_mode);
582 DPRINTF(5, ("done.\n"));
585 ttyld_close(tp, flag);
592 scread(struct cdev *dev, struct uio *uio, int flag)
594 if (!sc_saver_keyb_only)
595 sc_touch_scrn_saver();
596 return ttyread(dev, uio, flag);
600 sckbdevent(keyboard_t *thiskbd, int event, void *arg)
608 sc = (sc_softc_t *)arg;
609 /* assert(thiskbd == sc->kbd) */
614 case KBDIO_UNLOADING:
617 kbd_release(thiskbd, (void *)&sc->keyboard);
624 * Loop while there is still input to get from the keyboard.
625 * I don't think this is nessesary, and it doesn't fix
626 * the Xaccel-2.1 keyboard hang, but it can't hurt. XXX
628 while ((c = scgetc(sc, SCGETC_NONBLOCK)) != NOKEY) {
630 cur_tty = VIRTUAL_TTY(sc, sc->cur_scp->index);
631 if (!ISTTYOPEN(cur_tty)) {
632 cur_tty = sc_console_tty;
633 if (!ISTTYOPEN(cur_tty))
637 if ((*sc->cur_scp->tsw->te_input)(sc->cur_scp, c, cur_tty))
640 switch (KEYFLAGS(c)) {
641 case 0x0000: /* normal key */
642 ttyld_rint(cur_tty, KEYCHAR(c));
644 case FKEY: /* function key, return string */
645 cp = kbd_get_fkeystr(thiskbd, KEYCHAR(c), &len);
648 ttyld_rint(cur_tty, *cp++);
651 case MKEY: /* meta is active, prepend ESC */
652 ttyld_rint(cur_tty, 0x1b);
653 ttyld_rint(cur_tty, KEYCHAR(c));
655 case BKEY: /* backtab fixed sequence (esc [ Z) */
656 ttyld_rint(cur_tty, 0x1b);
657 ttyld_rint(cur_tty, '[');
658 ttyld_rint(cur_tty, 'Z');
663 sc->cur_scp->status |= MOUSE_HIDDEN;
669 scparam(struct tty *tp, struct termios *t)
671 tp->t_ispeed = t->c_ispeed;
672 tp->t_ospeed = t->c_ospeed;
673 tp->t_cflag = t->c_cflag;
678 scioctl(struct cdev *dev, u_long cmd, caddr_t data, int flag, struct thread *td)
686 #if defined(COMPAT_FREEBSD6) || defined(COMPAT_FREEBSD5) || \
687 defined(COMPAT_FREEBSD4) || defined(COMPAT_43)
693 /* If there is a user_ioctl function call that first */
695 error = (*sc_user_ioctl)(dev, cmd, data, flag, td);
696 if (error != ENOIOCTL)
700 error = sc_vid_ioctl(tp, cmd, data, flag, td);
701 if (error != ENOIOCTL)
704 #ifndef SC_NO_HISTORY
705 error = sc_hist_ioctl(tp, cmd, data, flag, td);
706 if (error != ENOIOCTL)
710 #ifndef SC_NO_SYSMOUSE
711 error = sc_mouse_ioctl(tp, cmd, data, flag, td);
712 if (error != ENOIOCTL)
716 scp = sc_get_stat(tp->t_dev);
717 /* assert(scp != NULL) */
718 /* scp is sc_console, if SC_VTY(dev) == SC_CONSOLECTL. */
722 error = (*scp->tsw->te_ioctl)(scp, tp, cmd, data, flag, td);
723 if (error != ENOIOCTL)
727 switch (cmd) { /* process console hardware related ioctl's */
729 case GIO_ATTR: /* get current attributes */
730 /* this ioctl is not processed here, but in the terminal emulator */
733 case GIO_COLOR: /* is this a color console ? */
734 *(int *)data = (sc->adp->va_flags & V_ADP_COLOR) ? 1 : 0;
737 case CONS_BLANKTIME: /* set screen saver timeout (0 = no saver) */
738 if (*(int *)data < 0 || *(int *)data > MAX_BLANKTIME)
741 scrn_blank_time = *(int *)data;
742 run_scrn_saver = (scrn_blank_time != 0);
746 case CONS_CURSORTYPE: /* set cursor type (obsolete) */
748 *(int *)data &= CONS_CURSOR_ATTRS;
749 sc_change_cursor_shape(scp, *(int *)data, -1, -1);
753 case CONS_GETCURSORSHAPE: /* get cursor shape (new interface) */
754 if (((int *)data)[0] & CONS_LOCAL_CURSOR) {
755 ((int *)data)[0] = scp->curr_curs_attr.flags;
756 ((int *)data)[1] = scp->curr_curs_attr.base;
757 ((int *)data)[2] = scp->curr_curs_attr.height;
759 ((int *)data)[0] = sc->curs_attr.flags;
760 ((int *)data)[1] = sc->curs_attr.base;
761 ((int *)data)[2] = sc->curs_attr.height;
765 case CONS_SETCURSORSHAPE: /* set cursor shape (new interface) */
767 sc_change_cursor_shape(scp, ((int *)data)[0],
768 ((int *)data)[1], ((int *)data)[2]);
772 case CONS_BELLTYPE: /* set bell type sound/visual */
773 if ((*(int *)data) & CONS_VISUAL_BELL)
774 sc->flags |= SC_VISUAL_BELL;
776 sc->flags &= ~SC_VISUAL_BELL;
777 if ((*(int *)data) & CONS_QUIET_BELL)
778 sc->flags |= SC_QUIET_BELL;
780 sc->flags &= ~SC_QUIET_BELL;
783 case CONS_GETINFO: /* get current (virtual) console info */
785 vid_info_t *ptr = (vid_info_t*)data;
786 if (ptr->size == sizeof(struct vid_info)) {
787 ptr->m_num = sc->cur_scp->index;
788 ptr->font_size = scp->font_size;
789 ptr->mv_col = scp->xpos;
790 ptr->mv_row = scp->ypos;
791 ptr->mv_csz = scp->xsize;
792 ptr->mv_rsz = scp->ysize;
793 ptr->mv_hsz = (scp->history != NULL) ? scp->history->vtb_rows : 0;
795 * The following fields are filled by the terminal emulator. XXX
802 ptr->mv_grfc.fore = 0; /* not supported */
803 ptr->mv_grfc.back = 0; /* not supported */
804 ptr->mv_ovscan = scp->border;
805 if (scp == sc->cur_scp)
807 ptr->mk_keylock = scp->status & LOCK_MASK;
813 case CONS_GETVERS: /* get version number */
814 *(int*)data = 0x200; /* version 2.0 */
817 case CONS_IDLE: /* see if the screen has been idle */
819 * When the screen is in the GRAPHICS_MODE or UNKNOWN_MODE,
820 * the user process may have been writing something on the
821 * screen and syscons is not aware of it. Declare the screen
822 * is NOT idle if it is in one of these modes. But there is
823 * an exception to it; if a screen saver is running in the
824 * graphics mode in the current screen, we should say that the
825 * screen has been idle.
827 *(int *)data = (sc->flags & SC_SCRN_IDLE)
828 && (!ISGRAPHSC(sc->cur_scp)
829 || (sc->cur_scp->status & SAVER_RUNNING));
832 case CONS_SAVERMODE: /* set saver mode */
833 switch(*(int *)data) {
836 /* if a LKM screen saver is running, stop it first. */
837 scsplash_stick(FALSE);
838 saver_mode = *(int *)data;
841 if ((error = wait_scrn_saver_stop(NULL))) {
846 run_scrn_saver = TRUE;
847 if (saver_mode == CONS_USR_SAVER)
848 scp->status |= SAVER_RUNNING;
850 scp->status &= ~SAVER_RUNNING;
851 scsplash_stick(TRUE);
856 if ((saver_mode == CONS_USR_SAVER) && (scp->status & SAVER_RUNNING))
857 scp->status &= ~SAVER_RUNNING;
858 saver_mode = *(int *)data;
866 case CONS_SAVERSTART: /* immediately start/stop the screen saver */
868 * Note that this ioctl does not guarantee the screen saver
869 * actually starts or stops. It merely attempts to do so...
872 run_scrn_saver = (*(int *)data != 0);
874 sc->scrn_time_stamp -= scrn_blank_time;
878 case CONS_SCRSHOT: /* get a screen shot */
880 int retval, hist_rsz;
882 vm_offset_t frbp, hstp;
884 scrshot_t *ptr = (scrshot_t *)data;
885 void *outp = ptr->buf;
887 if (ptr->x < 0 || ptr->y < 0 || ptr->xsize < 0 || ptr->ysize < 0)
890 if (ISGRAPHSC(scp)) {
894 hist_rsz = (scp->history != NULL) ? scp->history->vtb_rows : 0;
895 if (((u_int)ptr->x + ptr->xsize) > scp->xsize ||
896 ((u_int)ptr->y + ptr->ysize) > (scp->ysize + hist_rsz)) {
901 lsize = scp->xsize * sizeof(u_int16_t);
902 csize = ptr->xsize * sizeof(u_int16_t);
903 /* Pointer to the last line of framebuffer */
904 frbp = scp->vtb.vtb_buffer + scp->ysize * lsize + ptr->x *
906 /* Pointer to the last line of target buffer */
907 outp = (char *)outp + ptr->ysize * csize;
908 /* Pointer to the last line of history buffer */
909 if (scp->history != NULL)
910 hstp = scp->history->vtb_buffer + sc_vtb_tail(scp->history) *
911 sizeof(u_int16_t) + ptr->x * sizeof(u_int16_t);
916 for (lnum = 0; lnum < (ptr->y + ptr->ysize); lnum++) {
917 if (lnum < scp->ysize) {
921 if (hstp < scp->history->vtb_buffer)
922 hstp += scp->history->vtb_rows * lsize;
927 outp = (char *)outp - csize;
928 retval = copyout((void *)frbp, outp, csize);
936 case VT_SETMODE: /* set screen switcher mode */
938 struct vt_mode *mode;
941 mode = (struct vt_mode *)data;
942 DPRINTF(5, ("%s%d: VT_SETMODE ", SC_DRIVER_NAME, sc->unit));
943 if (scp->smode.mode == VT_PROCESS) {
944 p1 = pfind(scp->pid);
945 if (scp->proc == p1 && scp->proc != td->td_proc) {
948 DPRINTF(5, ("error EPERM\n"));
955 if (mode->mode == VT_AUTO) {
956 scp->smode.mode = VT_AUTO;
959 DPRINTF(5, ("VT_AUTO, "));
960 if ((scp == sc->cur_scp) && (sc->unit == sc_console_unit))
961 cnavailable(sc_consptr, TRUE);
962 /* were we in the middle of the vty switching process? */
963 if (finish_vt_rel(scp, TRUE, &s) == 0)
964 DPRINTF(5, ("reset WAIT_REL, "));
965 if (finish_vt_acq(scp) == 0)
966 DPRINTF(5, ("reset WAIT_ACQ, "));
968 if (!ISSIGVALID(mode->relsig) || !ISSIGVALID(mode->acqsig)
969 || !ISSIGVALID(mode->frsig)) {
971 DPRINTF(5, ("error EINVAL\n"));
974 DPRINTF(5, ("VT_PROCESS %d, ", td->td_proc->p_pid));
975 bcopy(data, &scp->smode, sizeof(struct vt_mode));
976 scp->proc = td->td_proc;
977 scp->pid = scp->proc->p_pid;
978 if ((scp == sc->cur_scp) && (sc->unit == sc_console_unit))
979 cnavailable(sc_consptr, FALSE);
986 case VT_GETMODE: /* get screen switcher mode */
987 bcopy(&scp->smode, data, sizeof(struct vt_mode));
990 #if defined(COMPAT_FREEBSD6) || defined(COMPAT_FREEBSD5) || \
991 defined(COMPAT_FREEBSD4) || defined(COMPAT_43)
993 ival = IOCPARM_IVAL(data);
994 data = (caddr_t)&ival;
997 case VT_RELDISP: /* screen switcher ioctl */
1000 * This must be the current vty which is in the VT_PROCESS
1003 if ((scp != sc->cur_scp) || (scp->smode.mode != VT_PROCESS)) {
1007 /* ...and this process is controlling it. */
1008 if (scp->proc != td->td_proc) {
1013 switch(*(int *)data) {
1014 case VT_FALSE: /* user refuses to release screen, abort */
1015 if ((error = finish_vt_rel(scp, FALSE, &s)) == 0)
1016 DPRINTF(5, ("%s%d: VT_FALSE\n", SC_DRIVER_NAME, sc->unit));
1018 case VT_TRUE: /* user has released screen, go on */
1019 if ((error = finish_vt_rel(scp, TRUE, &s)) == 0)
1020 DPRINTF(5, ("%s%d: VT_TRUE\n", SC_DRIVER_NAME, sc->unit));
1022 case VT_ACKACQ: /* acquire acknowledged, switch completed */
1023 if ((error = finish_vt_acq(scp)) == 0)
1024 DPRINTF(5, ("%s%d: VT_ACKACQ\n", SC_DRIVER_NAME, sc->unit));
1032 case VT_OPENQRY: /* return free virtual console */
1033 for (i = sc->first_vty; i < sc->first_vty + sc->vtys; i++) {
1034 tp = VIRTUAL_TTY(sc, i);
1035 if (!ISTTYOPEN(tp)) {
1036 *(int *)data = i + 1;
1042 #if defined(COMPAT_FREEBSD6) || defined(COMPAT_FREEBSD5) || \
1043 defined(COMPAT_FREEBSD4) || defined(COMPAT_43)
1045 ival = IOCPARM_IVAL(data);
1046 data = (caddr_t)&ival;
1049 case VT_ACTIVATE: /* switch to screen *data */
1050 i = (*(int *)data == 0) ? scp->index : (*(int *)data - 1);
1052 error = sc_clean_up(sc->cur_scp);
1056 return sc_switch_scr(sc, i);
1058 #if defined(COMPAT_FREEBSD6) || defined(COMPAT_FREEBSD5) || \
1059 defined(COMPAT_FREEBSD4) || defined(COMPAT_43)
1061 ival = IOCPARM_IVAL(data);
1062 data = (caddr_t)&ival;
1065 case VT_WAITACTIVE: /* wait for switch to occur */
1066 i = (*(int *)data == 0) ? scp->index : (*(int *)data - 1);
1067 if ((i < sc->first_vty) || (i >= sc->first_vty + sc->vtys))
1069 if (i == sc->cur_scp->index)
1071 error = tsleep(VTY_WCHAN(sc, i), (PZERO + 1) | PCATCH, "waitvt", 0);
1074 case VT_GETACTIVE: /* get active vty # */
1075 *(int *)data = sc->cur_scp->index + 1;
1078 case VT_GETINDEX: /* get this vty # */
1079 *(int *)data = scp->index + 1;
1082 case VT_LOCKSWITCH: /* prevent vty switching */
1083 if ((*(int *)data) & 0x01)
1084 sc->flags |= SC_SCRN_VTYLOCK;
1086 sc->flags &= ~SC_SCRN_VTYLOCK;
1089 case KDENABIO: /* allow io operations */
1090 error = priv_check(td, PRIV_IO);
1093 error = securelevel_gt(td->td_ucred, 0);
1097 td->td_frame->tf_eflags |= PSL_IOPL;
1098 #elif defined(__amd64__)
1099 td->td_frame->tf_rflags |= PSL_IOPL;
1103 case KDDISABIO: /* disallow io operations (default) */
1105 td->td_frame->tf_eflags &= ~PSL_IOPL;
1106 #elif defined(__amd64__)
1107 td->td_frame->tf_rflags &= ~PSL_IOPL;
1111 #if defined(COMPAT_FREEBSD6) || defined(COMPAT_FREEBSD5) || \
1112 defined(COMPAT_FREEBSD4) || defined(COMPAT_43)
1114 ival = IOCPARM_IVAL(data);
1115 data = (caddr_t)&ival;
1118 case KDSKBSTATE: /* set keyboard state (locks) */
1119 if (*(int *)data & ~LOCK_MASK)
1121 scp->status &= ~LOCK_MASK;
1122 scp->status |= *(int *)data;
1123 if (scp == sc->cur_scp)
1124 update_kbd_state(scp, scp->status, LOCK_MASK);
1127 case KDGKBSTATE: /* get keyboard state (locks) */
1128 if (scp == sc->cur_scp)
1129 save_kbd_state(scp);
1130 *(int *)data = scp->status & LOCK_MASK;
1133 case KDGETREPEAT: /* get keyboard repeat & delay rates */
1134 case KDSETREPEAT: /* set keyboard repeat & delay rates (new) */
1135 error = kbd_ioctl(sc->kbd, cmd, data);
1136 if (error == ENOIOCTL)
1140 #if defined(COMPAT_FREEBSD6) || defined(COMPAT_FREEBSD5) || \
1141 defined(COMPAT_FREEBSD4) || defined(COMPAT_43)
1143 ival = IOCPARM_IVAL(data);
1144 data = (caddr_t)&ival;
1147 case KDSETRAD: /* set keyboard repeat & delay rates (old) */
1148 if (*(int *)data & ~0x7f)
1150 error = kbd_ioctl(sc->kbd, KDSETRAD, data);
1151 if (error == ENOIOCTL)
1155 #if defined(COMPAT_FREEBSD6) || defined(COMPAT_FREEBSD5) || \
1156 defined(COMPAT_FREEBSD4) || defined(COMPAT_43)
1158 ival = IOCPARM_IVAL(data);
1159 data = (caddr_t)&ival;
1162 case KDSKBMODE: /* set keyboard mode */
1163 switch (*(int *)data) {
1164 case K_XLATE: /* switch to XLT ascii mode */
1165 case K_RAW: /* switch to RAW scancode mode */
1166 case K_CODE: /* switch to CODE mode */
1167 scp->kbd_mode = *(int *)data;
1168 if (scp == sc->cur_scp)
1169 kbd_ioctl(sc->kbd, KDSKBMODE, data);
1176 case KDGKBMODE: /* get keyboard mode */
1177 *(int *)data = scp->kbd_mode;
1181 error = kbd_ioctl(sc->kbd, cmd, data);
1182 if (error == ENOIOCTL)
1186 #if defined(COMPAT_FREEBSD6) || defined(COMPAT_FREEBSD5) || \
1187 defined(COMPAT_FREEBSD4) || defined(COMPAT_43)
1189 ival = IOCPARM_IVAL(data);
1190 data = (caddr_t)&ival;
1193 case KDMKTONE: /* sound the bell */
1195 sc_bell(scp, (*(int*)data)&0xffff,
1196 (((*(int*)data)>>16)&0xffff)*hz/1000);
1198 sc_bell(scp, scp->bell_pitch, scp->bell_duration);
1201 #if defined(COMPAT_FREEBSD6) || defined(COMPAT_FREEBSD5) || \
1202 defined(COMPAT_FREEBSD4) || defined(COMPAT_43)
1204 ival = IOCPARM_IVAL(data);
1205 data = (caddr_t)&ival;
1208 case KIOCSOUND: /* make tone (*data) hz */
1209 if (scp == sc->cur_scp) {
1211 return sc_tone(*(int *)data);
1217 case KDGKBTYPE: /* get keyboard type */
1218 error = kbd_ioctl(sc->kbd, cmd, data);
1219 if (error == ENOIOCTL) {
1220 /* always return something? XXX */
1225 #if defined(COMPAT_FREEBSD6) || defined(COMPAT_FREEBSD5) || \
1226 defined(COMPAT_FREEBSD4) || defined(COMPAT_43)
1228 ival = IOCPARM_IVAL(data);
1229 data = (caddr_t)&ival;
1232 case KDSETLED: /* set keyboard LED status */
1233 if (*(int *)data & ~LED_MASK) /* FIXME: LOCK_MASK? */
1235 scp->status &= ~LED_MASK;
1236 scp->status |= *(int *)data;
1237 if (scp == sc->cur_scp)
1238 update_kbd_leds(scp, scp->status);
1241 case KDGETLED: /* get keyboard LED status */
1242 if (scp == sc->cur_scp)
1243 save_kbd_state(scp);
1244 *(int *)data = scp->status & LED_MASK;
1247 case KBADDKBD: /* add/remove keyboard to/from mux */
1249 error = kbd_ioctl(sc->kbd, cmd, data);
1250 if (error == ENOIOCTL)
1254 #if defined(COMPAT_FREEBSD6) || defined(COMPAT_FREEBSD5) || \
1255 defined(COMPAT_FREEBSD4) || defined(COMPAT_43)
1257 ival = IOCPARM_IVAL(data);
1258 data = (caddr_t)&ival;
1261 case CONS_SETKBD: /* set the new keyboard */
1266 newkbd = kbd_get_keyboard(*(int *)data);
1267 if (newkbd == NULL) {
1272 if (sc->kbd != newkbd) {
1273 i = kbd_allocate(newkbd->kb_name, newkbd->kb_unit,
1274 (void *)&sc->keyboard, sckbdevent, sc);
1275 /* i == newkbd->kb_index */
1277 if (sc->kbd != NULL) {
1278 save_kbd_state(sc->cur_scp);
1279 kbd_release(sc->kbd, (void *)&sc->keyboard);
1281 sc->kbd = kbd_get_keyboard(i); /* sc->kbd == newkbd */
1283 kbd_ioctl(sc->kbd, KDSKBMODE,
1284 (caddr_t)&sc->cur_scp->kbd_mode);
1285 update_kbd_state(sc->cur_scp, sc->cur_scp->status,
1288 error = EPERM; /* XXX */
1295 case CONS_RELKBD: /* release the current keyboard */
1298 if (sc->kbd != NULL) {
1299 save_kbd_state(sc->cur_scp);
1300 error = kbd_release(sc->kbd, (void *)&sc->keyboard);
1309 case CONS_GETTERM: /* get the current terminal emulator info */
1313 if (((term_info_t *)data)->ti_index == 0) {
1316 sw = sc_term_match_by_number(((term_info_t *)data)->ti_index);
1319 strncpy(((term_info_t *)data)->ti_name, sw->te_name,
1320 sizeof(((term_info_t *)data)->ti_name));
1321 strncpy(((term_info_t *)data)->ti_desc, sw->te_desc,
1322 sizeof(((term_info_t *)data)->ti_desc));
1323 ((term_info_t *)data)->ti_flags = 0;
1326 ((term_info_t *)data)->ti_name[0] = '\0';
1327 ((term_info_t *)data)->ti_desc[0] = '\0';
1328 ((term_info_t *)data)->ti_flags = 0;
1333 case CONS_SETTERM: /* set the current terminal emulator */
1335 error = sc_init_emulator(scp, ((term_info_t *)data)->ti_name);
1336 /* FIXME: what if scp == sc_console! XXX */
1340 case GIO_SCRNMAP: /* get output translation table */
1341 bcopy(&sc->scr_map, data, sizeof(sc->scr_map));
1344 case PIO_SCRNMAP: /* set output translation table */
1345 bcopy(data, &sc->scr_map, sizeof(sc->scr_map));
1346 for (i=0; i<sizeof(sc->scr_map); i++) {
1347 sc->scr_rmap[sc->scr_map[i]] = i;
1351 case GIO_KEYMAP: /* get keyboard translation table */
1352 case PIO_KEYMAP: /* set keyboard translation table */
1353 case GIO_DEADKEYMAP: /* get accent key translation table */
1354 case PIO_DEADKEYMAP: /* set accent key translation table */
1355 case GETFKEY: /* get function key string */
1356 case SETFKEY: /* set function key string */
1357 error = kbd_ioctl(sc->kbd, cmd, data);
1358 if (error == ENOIOCTL)
1362 #ifndef SC_NO_FONT_LOADING
1364 case PIO_FONT8x8: /* set 8x8 dot font */
1365 if (!ISFONTAVAIL(sc->adp->va_flags))
1367 bcopy(data, sc->font_8, 8*256);
1368 sc->fonts_loaded |= FONT_8;
1371 * Always use the font page #0. XXX
1372 * Don't load if the current font size is not 8x8.
1374 if (ISTEXTSC(sc->cur_scp) && (sc->cur_scp->font_size < 14))
1375 sc_load_font(sc->cur_scp, 0, 8, 8, sc->font_8, 0, 256);
1378 case GIO_FONT8x8: /* get 8x8 dot font */
1379 if (!ISFONTAVAIL(sc->adp->va_flags))
1381 if (sc->fonts_loaded & FONT_8) {
1382 bcopy(sc->font_8, data, 8*256);
1388 case PIO_FONT8x14: /* set 8x14 dot font */
1389 if (!ISFONTAVAIL(sc->adp->va_flags))
1391 bcopy(data, sc->font_14, 14*256);
1392 sc->fonts_loaded |= FONT_14;
1395 * Always use the font page #0. XXX
1396 * Don't load if the current font size is not 8x14.
1398 if (ISTEXTSC(sc->cur_scp)
1399 && (sc->cur_scp->font_size >= 14)
1400 && (sc->cur_scp->font_size < 16))
1401 sc_load_font(sc->cur_scp, 0, 14, 8, sc->font_14, 0, 256);
1404 case GIO_FONT8x14: /* get 8x14 dot font */
1405 if (!ISFONTAVAIL(sc->adp->va_flags))
1407 if (sc->fonts_loaded & FONT_14) {
1408 bcopy(sc->font_14, data, 14*256);
1414 case PIO_FONT8x16: /* set 8x16 dot font */
1415 if (!ISFONTAVAIL(sc->adp->va_flags))
1417 bcopy(data, sc->font_16, 16*256);
1418 sc->fonts_loaded |= FONT_16;
1421 * Always use the font page #0. XXX
1422 * Don't load if the current font size is not 8x16.
1424 if (ISTEXTSC(sc->cur_scp) && (sc->cur_scp->font_size >= 16))
1425 sc_load_font(sc->cur_scp, 0, 16, 8, sc->font_16, 0, 256);
1428 case GIO_FONT8x16: /* get 8x16 dot font */
1429 if (!ISFONTAVAIL(sc->adp->va_flags))
1431 if (sc->fonts_loaded & FONT_16) {
1432 bcopy(sc->font_16, data, 16*256);
1438 #endif /* SC_NO_FONT_LOADING */
1444 return (ttyioctl(dev, cmd, data, flag, td));
1448 scstart(struct tty *tp)
1452 u_char buf[PCBURST];
1453 scr_stat *scp = sc_get_stat(tp->t_dev);
1455 if (scp->status & SLKED ||
1456 (scp == scp->sc->cur_scp && scp->sc->blink_in_progress))
1459 if (!(tp->t_state & (TS_TIMEOUT | TS_BUSY | TS_TTSTOP))) {
1460 tp->t_state |= TS_BUSY;
1463 len = q_to_b(rbp, buf, PCBURST);
1465 sc_puts(scp, buf, len);
1468 tp->t_state &= ~TS_BUSY;
1475 sc_cnprobe(struct consdev *cp)
1480 cp->cn_pri = sc_get_cons_priority(&unit, &flags);
1482 /* a video card is always required */
1483 if (!scvidprobe(unit, flags, TRUE))
1484 cp->cn_pri = CN_DEAD;
1486 /* syscons will become console even when there is no keyboard */
1487 sckbdprobe(unit, flags, TRUE);
1489 if (cp->cn_pri == CN_DEAD)
1492 /* initialize required fields */
1493 sprintf(cp->cn_name, "consolectl");
1497 sc_cninit(struct consdev *cp)
1502 sc_get_cons_priority(&unit, &flags);
1503 scinit(unit, flags | SC_KERNEL_CONSOLE);
1504 sc_console_unit = unit;
1505 sc_console = sc_get_stat(sc_get_softc(unit, SC_KERNEL_CONSOLE)->dev[0]);
1510 sc_cnterm(struct consdev *cp)
1512 /* we are not the kernel console any more, release everything */
1514 if (sc_console_unit < 0)
1515 return; /* shouldn't happen */
1518 sc_clear_screen(sc_console);
1519 sccnupdate(sc_console);
1522 scterm(sc_console_unit, SC_KERNEL_CONSOLE);
1523 sc_console_unit = -1;
1528 sc_cnputc(struct consdev *cd, int c)
1531 scr_stat *scp = sc_console;
1533 #ifndef SC_NO_HISTORY
1535 #endif /* !SC_NO_HISTORY */
1538 /* assert(sc_console != NULL) */
1540 #ifndef SC_NO_HISTORY
1541 if (scp == scp->sc->cur_scp && scp->status & SLKED) {
1542 scp->status &= ~SLKED;
1543 update_kbd_state(scp, scp->status, SLKED);
1544 if (scp->status & BUFFER_SAVED) {
1545 if (!sc_hist_restore(scp))
1546 sc_remove_cutmarking(scp);
1547 scp->status &= ~BUFFER_SAVED;
1548 scp->status |= CURSOR_ENABLED;
1549 sc_draw_cursor_image(scp);
1551 tp = VIRTUAL_TTY(scp->sc, scp->index);
1555 #endif /* !SC_NO_HISTORY */
1558 if (kernel_console_ts != NULL)
1559 scp->ts = kernel_console_ts;
1561 sc_puts(scp, buf, 1);
1564 s = spltty(); /* block sckbdevent and scrn_timer */
1570 sc_cngetc(struct consdev *cd)
1572 return sccngetch(SCGETC_NONBLOCK);
1576 sccngetch(int flags)
1578 static struct fkeytab fkey;
1583 int s = spltty(); /* block sckbdevent and scrn_timer while we poll */
1586 /* assert(sc_console != NULL) */
1589 * Stop the screen saver and update the screen if necessary.
1590 * What if we have been running in the screen saver code... XXX
1592 sc_touch_scrn_saver();
1593 scp = sc_console->sc->cur_scp; /* XXX */
1596 if (fkeycp < fkey.len) {
1598 return fkey.str[fkeycp++];
1601 if (scp->sc->kbd == NULL) {
1607 * Make sure the keyboard is accessible even when the kbd device
1608 * driver is disabled.
1610 kbd_enable(scp->sc->kbd);
1612 /* we shall always use the keyboard in the XLATE mode here */
1613 cur_mode = scp->kbd_mode;
1614 scp->kbd_mode = K_XLATE;
1615 kbd_ioctl(scp->sc->kbd, KDSKBMODE, (caddr_t)&scp->kbd_mode);
1617 kbd_poll(scp->sc->kbd, TRUE);
1618 c = scgetc(scp->sc, SCGETC_CN | flags);
1619 kbd_poll(scp->sc->kbd, FALSE);
1621 scp->kbd_mode = cur_mode;
1622 kbd_ioctl(scp->sc->kbd, KDSKBMODE, (caddr_t)&scp->kbd_mode);
1623 kbd_disable(scp->sc->kbd);
1626 switch (KEYFLAGS(c)) {
1627 case 0: /* normal char */
1629 case FKEY: /* function key */
1630 p = kbd_get_fkeystr(scp->sc->kbd, KEYCHAR(c), (size_t *)&fkeycp);
1632 if ((p != NULL) && (fkey.len > 0)) {
1633 bcopy(p, fkey.str, fkey.len);
1647 sccnupdate(scr_stat *scp)
1649 /* this is a cut-down version of scrn_timer()... */
1651 if (scp->sc->font_loading_in_progress)
1654 if (debugger > 0 || panicstr || shutdown_in_progress) {
1655 sc_touch_scrn_saver();
1656 } else if (scp != scp->sc->cur_scp) {
1660 if (!run_scrn_saver)
1661 scp->sc->flags &= ~SC_SCRN_IDLE;
1663 if ((saver_mode != CONS_LKM_SAVER) || !(scp->sc->flags & SC_SCRN_IDLE))
1664 if (scp->sc->flags & SC_SCRN_BLANKED)
1665 stop_scrn_saver(scp->sc, current_saver);
1668 if (scp != scp->sc->cur_scp || scp->sc->blink_in_progress
1669 || scp->sc->switch_in_progress)
1672 * FIXME: unlike scrn_timer(), we call scrn_update() from here even
1673 * when write_in_progress is non-zero. XXX
1676 if (!ISGRAPHSC(scp) && !(scp->sc->flags & SC_SCRN_BLANKED))
1677 scrn_update(scp, TRUE);
1681 scrn_timer(void *arg)
1684 static int kbd_interval = 0;
1692 again = (arg != NULL);
1694 sc = (sc_softc_t *)arg;
1695 else if (sc_console != NULL)
1696 sc = sc_console->sc;
1700 /* don't do anything when we are performing some I/O operations */
1701 if (sc->font_loading_in_progress) {
1703 timeout(scrn_timer, sc, hz / 10);
1709 if ((sc->kbd == NULL) && (sc->config & SC_AUTODETECT_KBD)) {
1710 /* try to allocate a keyboard automatically */
1711 if (++kbd_interval >= 25) {
1712 sc->keyboard = sc_allocate_keyboard(sc, -1);
1713 if (sc->keyboard >= 0) {
1714 sc->kbd = kbd_get_keyboard(sc->keyboard);
1715 kbd_ioctl(sc->kbd, KDSKBMODE,
1716 (caddr_t)&sc->cur_scp->kbd_mode);
1717 update_kbd_state(sc->cur_scp, sc->cur_scp->status,
1725 /* find the vty to update */
1728 /* should we stop the screen saver? */
1729 getmicrouptime(&tv);
1730 if (debugger > 0 || panicstr || shutdown_in_progress)
1731 sc_touch_scrn_saver();
1732 if (run_scrn_saver) {
1733 if (tv.tv_sec > sc->scrn_time_stamp + scrn_blank_time)
1734 sc->flags |= SC_SCRN_IDLE;
1736 sc->flags &= ~SC_SCRN_IDLE;
1738 sc->scrn_time_stamp = tv.tv_sec;
1739 sc->flags &= ~SC_SCRN_IDLE;
1740 if (scrn_blank_time > 0)
1741 run_scrn_saver = TRUE;
1744 if ((saver_mode != CONS_LKM_SAVER) || !(sc->flags & SC_SCRN_IDLE))
1745 if (sc->flags & SC_SCRN_BLANKED)
1746 stop_scrn_saver(sc, current_saver);
1749 /* should we just return ? */
1750 if (sc->blink_in_progress || sc->switch_in_progress
1751 || sc->write_in_progress) {
1753 timeout(scrn_timer, sc, hz / 10);
1758 /* Update the screen */
1759 scp = sc->cur_scp; /* cur_scp may have changed... */
1760 if (!ISGRAPHSC(scp) && !(sc->flags & SC_SCRN_BLANKED))
1761 scrn_update(scp, TRUE);
1764 /* should we activate the screen saver? */
1765 if ((saver_mode == CONS_LKM_SAVER) && (sc->flags & SC_SCRN_IDLE))
1766 if (!ISGRAPHSC(scp) || (sc->flags & SC_SCRN_BLANKED))
1767 (*current_saver)(sc, TRUE);
1771 timeout(scrn_timer, sc, hz / 25);
1776 and_region(int *s1, int *e1, int s2, int e2)
1778 if (*e1 < s2 || e2 < *s1)
1780 *s1 = imax(*s1, s2);
1781 *e1 = imin(*e1, e2);
1786 scrn_update(scr_stat *scp, int show_cursor)
1793 /* assert(scp == scp->sc->cur_scp) */
1795 SC_VIDEO_LOCK(scp->sc);
1797 #ifndef SC_NO_CUTPASTE
1798 /* remove the previous mouse pointer image if necessary */
1799 if (scp->status & MOUSE_VISIBLE) {
1801 e = scp->mouse_pos + scp->xsize + 1;
1802 if ((scp->status & (MOUSE_MOVED | MOUSE_HIDDEN))
1803 || and_region(&s, &e, scp->start, scp->end)
1804 || ((scp->status & CURSOR_ENABLED) &&
1805 (scp->cursor_pos != scp->cursor_oldpos) &&
1806 (and_region(&s, &e, scp->cursor_pos, scp->cursor_pos)
1807 || and_region(&s, &e, scp->cursor_oldpos, scp->cursor_oldpos)))) {
1808 sc_remove_mouse_image(scp);
1809 if (scp->end >= scp->xsize*scp->ysize)
1810 scp->end = scp->xsize*scp->ysize - 1;
1813 #endif /* !SC_NO_CUTPASTE */
1817 if (scp->end >= scp->xsize*scp->ysize) {
1818 printf("scrn_update(): scp->end %d > size_of_screen!!\n", scp->end);
1819 scp->end = scp->xsize*scp->ysize - 1;
1821 if (scp->start < 0) {
1822 printf("scrn_update(): scp->start %d < 0\n", scp->start);
1827 /* update screen image */
1828 if (scp->start <= scp->end) {
1829 if (scp->mouse_cut_end >= 0) {
1830 /* there is a marked region for cut & paste */
1831 if (scp->mouse_cut_start <= scp->mouse_cut_end) {
1832 start = scp->mouse_cut_start;
1833 end = scp->mouse_cut_end;
1835 start = scp->mouse_cut_end;
1836 end = scp->mouse_cut_start - 1;
1840 /* does the cut-mark region overlap with the update region? */
1841 if (and_region(&s, &e, scp->start, scp->end)) {
1842 (*scp->rndr->draw)(scp, s, e - s + 1, TRUE);
1845 if (and_region(&s, &e, scp->start, scp->end))
1846 (*scp->rndr->draw)(scp, s, e - s + 1, FALSE);
1848 e = scp->xsize*scp->ysize - 1;
1849 if (and_region(&s, &e, scp->start, scp->end))
1850 (*scp->rndr->draw)(scp, s, e - s + 1, FALSE);
1852 (*scp->rndr->draw)(scp, scp->start,
1853 scp->end - scp->start + 1, FALSE);
1856 (*scp->rndr->draw)(scp, scp->start,
1857 scp->end - scp->start + 1, FALSE);
1861 /* we are not to show the cursor and the mouse pointer... */
1864 scp->start = scp->xsize*scp->ysize - 1;
1865 SC_VIDEO_UNLOCK(scp->sc);
1869 /* update cursor image */
1870 if (scp->status & CURSOR_ENABLED) {
1873 /* did cursor move since last time ? */
1874 if (scp->cursor_pos != scp->cursor_oldpos) {
1875 /* do we need to remove old cursor image ? */
1876 if (!and_region(&s, &e, scp->cursor_oldpos, scp->cursor_oldpos))
1877 sc_remove_cursor_image(scp);
1878 sc_draw_cursor_image(scp);
1880 if (and_region(&s, &e, scp->cursor_pos, scp->cursor_pos))
1881 /* cursor didn't move, but has been overwritten */
1882 sc_draw_cursor_image(scp);
1883 else if (scp->curs_attr.flags & CONS_BLINK_CURSOR)
1884 /* if it's a blinking cursor, update it */
1885 (*scp->rndr->blink_cursor)(scp, scp->cursor_pos,
1886 sc_inside_cutmark(scp,
1891 #ifndef SC_NO_CUTPASTE
1892 /* update "pseudo" mouse pointer image */
1893 if (scp->sc->flags & SC_MOUSE_ENABLED) {
1894 if (!(scp->status & (MOUSE_VISIBLE | MOUSE_HIDDEN))) {
1895 scp->status &= ~MOUSE_MOVED;
1896 sc_draw_mouse_image(scp);
1899 #endif /* SC_NO_CUTPASTE */
1902 scp->start = scp->xsize*scp->ysize - 1;
1904 SC_VIDEO_UNLOCK(scp->sc);
1909 scsplash_callback(int event, void *arg)
1914 sc = (sc_softc_t *)arg;
1918 if (add_scrn_saver(scsplash_saver) == 0) {
1919 sc->flags &= ~SC_SAVER_FAILED;
1920 run_scrn_saver = TRUE;
1921 if (cold && !(boothowto & RB_VERBOSE)) {
1922 scsplash_stick(TRUE);
1923 (*current_saver)(sc, TRUE);
1929 if (current_saver == scsplash_saver) {
1930 scsplash_stick(FALSE);
1931 error = remove_scrn_saver(scsplash_saver);
1943 scsplash_saver(sc_softc_t *sc, int show)
1945 static int busy = FALSE;
1954 if (!(sc->flags & SC_SAVER_FAILED)) {
1955 if (!(sc->flags & SC_SCRN_BLANKED))
1956 set_scrn_saver_mode(scp, -1, NULL, 0);
1957 switch (splash(sc->adp, TRUE)) {
1958 case 0: /* succeeded */
1960 case EAGAIN: /* try later */
1961 restore_scrn_saver_mode(scp, FALSE);
1962 sc_touch_scrn_saver(); /* XXX */
1965 sc->flags |= SC_SAVER_FAILED;
1966 scsplash_stick(FALSE);
1967 restore_scrn_saver_mode(scp, TRUE);
1968 printf("scsplash_saver(): failed to put up the image\n");
1972 } else if (!sticky_splash) {
1973 if ((sc->flags & SC_SCRN_BLANKED) && (splash(sc->adp, FALSE) == 0))
1974 restore_scrn_saver_mode(scp, TRUE);
1980 add_scrn_saver(void (*this_saver)(sc_softc_t *, int))
1985 if (current_saver != none_saver) {
1986 error = remove_scrn_saver(current_saver);
1991 if (current_saver != none_saver)
1994 run_scrn_saver = FALSE;
1995 saver_mode = CONS_LKM_SAVER;
1996 current_saver = this_saver;
2001 remove_scrn_saver(void (*this_saver)(sc_softc_t *, int))
2003 if (current_saver != this_saver)
2008 * In order to prevent `current_saver' from being called by
2009 * the timeout routine `scrn_timer()' while we manipulate
2010 * the saver list, we shall set `current_saver' to `none_saver'
2011 * before stopping the current saver, rather than blocking by `splXX()'.
2013 current_saver = none_saver;
2015 stop_scrn_saver(this_saver);
2018 /* unblank all blanked screens */
2019 wait_scrn_saver_stop(NULL);
2023 current_saver = none_saver;
2028 set_scrn_saver_mode(scr_stat *scp, int mode, u_char *pal, int border)
2032 /* assert(scp == scp->sc->cur_scp) */
2034 if (!ISGRAPHSC(scp))
2035 sc_remove_cursor_image(scp);
2036 scp->splash_save_mode = scp->mode;
2037 scp->splash_save_status = scp->status & (GRAPHICS_MODE | PIXEL_MODE);
2038 scp->status &= ~(GRAPHICS_MODE | PIXEL_MODE);
2039 scp->status |= (UNKNOWN_MODE | SAVER_RUNNING);
2040 scp->sc->flags |= SC_SCRN_BLANKED;
2046 if (set_mode(scp) == 0) {
2047 if (scp->sc->adp->va_info.vi_flags & V_INFO_GRAPHICS)
2048 scp->status |= GRAPHICS_MODE;
2049 #ifndef SC_NO_PALETTE_LOADING
2051 load_palette(scp->sc->adp, pal);
2053 sc_set_border(scp, border);
2057 scp->mode = scp->splash_save_mode;
2058 scp->status &= ~(UNKNOWN_MODE | SAVER_RUNNING);
2059 scp->status |= scp->splash_save_status;
2066 restore_scrn_saver_mode(scr_stat *scp, int changemode)
2072 /* assert(scp == scp->sc->cur_scp) */
2075 status = scp->status;
2076 scp->mode = scp->splash_save_mode;
2077 scp->status &= ~(UNKNOWN_MODE | SAVER_RUNNING);
2078 scp->status |= scp->splash_save_status;
2079 scp->sc->flags &= ~SC_SCRN_BLANKED;
2081 if (!ISGRAPHSC(scp))
2082 sc_draw_cursor_image(scp);
2087 if (set_mode(scp) == 0) {
2088 #ifndef SC_NO_PALETTE_LOADING
2089 load_palette(scp->sc->adp, scp->sc->palette);
2096 scp->status = status;
2103 stop_scrn_saver(sc_softc_t *sc, void (*saver)(sc_softc_t *, int))
2105 (*saver)(sc, FALSE);
2106 run_scrn_saver = FALSE;
2107 /* the screen saver may have chosen not to stop after all... */
2108 if (sc->flags & SC_SCRN_BLANKED)
2111 mark_all(sc->cur_scp);
2112 if (sc->delayed_next_scr)
2113 sc_switch_scr(sc, sc->delayed_next_scr - 1);
2115 wakeup(&scrn_blanked);
2119 wait_scrn_saver_stop(sc_softc_t *sc)
2123 while (scrn_blanked > 0) {
2124 run_scrn_saver = FALSE;
2125 if (sc && !(sc->flags & SC_SCRN_BLANKED)) {
2129 error = tsleep(&scrn_blanked, PZERO | PCATCH, "scrsav", 0);
2130 if ((error != 0) && (error != ERESTART))
2133 run_scrn_saver = FALSE;
2136 #endif /* DEV_SPLASH */
2139 sc_touch_scrn_saver(void)
2141 scsplash_stick(FALSE);
2142 run_scrn_saver = FALSE;
2146 sc_switch_scr(sc_softc_t *sc, u_int next_scr)
2153 DPRINTF(5, ("sc0: sc_switch_scr() %d ", next_scr + 1));
2155 if (sc->cur_scp == NULL)
2158 /* prevent switch if previously requested */
2159 if (sc->flags & SC_SCRN_VTYLOCK) {
2160 sc_bell(sc->cur_scp, sc->cur_scp->bell_pitch,
2161 sc->cur_scp->bell_duration);
2165 /* delay switch if the screen is blanked or being updated */
2166 if ((sc->flags & SC_SCRN_BLANKED) || sc->write_in_progress
2167 || sc->blink_in_progress) {
2168 sc->delayed_next_scr = next_scr + 1;
2169 sc_touch_scrn_saver();
2170 DPRINTF(5, ("switch delayed\n"));
2173 sc->delayed_next_scr = 0;
2176 cur_scp = sc->cur_scp;
2178 /* we are in the middle of the vty switching process... */
2179 if (sc->switch_in_progress
2180 && (cur_scp->smode.mode == VT_PROCESS)
2182 p = pfind(cur_scp->pid);
2183 if (cur_scp->proc != p) {
2187 * The controlling process has died!!. Do some clean up.
2188 * NOTE:`cur_scp->proc' and `cur_scp->smode.mode'
2189 * are not reset here yet; they will be cleared later.
2191 DPRINTF(5, ("cur_scp controlling process %d died, ",
2193 if (cur_scp->status & SWITCH_WAIT_REL) {
2195 * Force the previous switch to finish, but return now
2198 DPRINTF(5, ("reset WAIT_REL, "));
2199 finish_vt_rel(cur_scp, TRUE, &s);
2201 DPRINTF(5, ("finishing previous switch\n"));
2203 } else if (cur_scp->status & SWITCH_WAIT_ACQ) {
2204 /* let's assume screen switch has been completed. */
2205 DPRINTF(5, ("reset WAIT_ACQ, "));
2206 finish_vt_acq(cur_scp);
2209 * We are in between screen release and acquisition, and
2210 * reached here via scgetc() or scrn_timer() which has
2211 * interrupted exchange_scr(). Don't do anything stupid.
2213 DPRINTF(5, ("waiting nothing, "));
2219 * The controlling process is alive, but not responding...
2220 * It is either buggy or it may be just taking time.
2221 * The following code is a gross kludge to cope with this
2222 * problem for which there is no clean solution. XXX
2224 if (cur_scp->status & SWITCH_WAIT_REL) {
2225 switch (sc->switch_in_progress++) {
2229 DPRINTF(5, ("sending relsig again, "));
2230 signal_vt_rel(cur_scp);
2237 * Act as if the controlling program returned
2240 DPRINTF(5, ("force reset WAIT_REL, "));
2241 finish_vt_rel(cur_scp, FALSE, &s);
2243 DPRINTF(5, ("act as if VT_FALSE was seen\n"));
2246 } else if (cur_scp->status & SWITCH_WAIT_ACQ) {
2247 switch (sc->switch_in_progress++) {
2251 DPRINTF(5, ("sending acqsig again, "));
2252 signal_vt_acq(cur_scp);
2258 /* clear the flag and finish the previous switch */
2259 DPRINTF(5, ("force reset WAIT_ACQ, "));
2260 finish_vt_acq(cur_scp);
2268 * Return error if an invalid argument is given, or vty switch
2269 * is still in progress.
2271 if ((next_scr < sc->first_vty) || (next_scr >= sc->first_vty + sc->vtys)
2272 || sc->switch_in_progress) {
2274 sc_bell(cur_scp, bios_value.bell_pitch, BELL_DURATION);
2275 DPRINTF(5, ("error 1\n"));
2280 * Don't allow switching away from the graphics mode vty
2281 * if the switch mode is VT_AUTO, unless the next vty is the same
2282 * as the current or the current vty has been closed (but showing).
2284 tp = VIRTUAL_TTY(sc, cur_scp->index);
2285 if ((cur_scp->index != next_scr)
2287 && (cur_scp->smode.mode == VT_AUTO)
2288 && ISGRAPHSC(cur_scp)) {
2290 sc_bell(cur_scp, bios_value.bell_pitch, BELL_DURATION);
2291 DPRINTF(5, ("error, graphics mode\n"));
2296 * Is the wanted vty open? Don't allow switching to a closed vty.
2297 * If we are in DDB, don't switch to a vty in the VT_PROCESS mode.
2298 * Note that we always allow the user to switch to the kernel
2299 * console even if it is closed.
2301 if ((sc_console == NULL) || (next_scr != sc_console->index)) {
2302 tp = VIRTUAL_TTY(sc, next_scr);
2303 if (!ISTTYOPEN(tp)) {
2305 sc_bell(cur_scp, bios_value.bell_pitch, BELL_DURATION);
2306 DPRINTF(5, ("error 2, requested vty isn't open!\n"));
2309 if ((debugger > 0) && (SC_STAT(tp->t_dev)->smode.mode == VT_PROCESS)) {
2311 DPRINTF(5, ("error 3, requested vty is in the VT_PROCESS mode\n"));
2316 /* this is the start of vty switching process... */
2317 ++sc->switch_in_progress;
2318 sc->old_scp = cur_scp;
2319 sc->new_scp = sc_get_stat(SC_DEV(sc, next_scr));
2320 if (sc->new_scp == sc->old_scp) {
2321 sc->switch_in_progress = 0;
2323 * XXX wakeup() locks the scheduler lock which will hang if
2324 * the lock is in an in-between state, e.g., when we stop at
2325 * a breakpoint at fork_exit. It has always been wrong to call
2326 * wakeup() when the debugger is active. In RELENG_4, wakeup()
2327 * is supposed to be locked by splhigh(), but the debugger may
2328 * be invoked at splhigh().
2331 wakeup(VTY_WCHAN(sc,next_scr));
2333 DPRINTF(5, ("switch done (new == old)\n"));
2337 /* has controlling process died? */
2338 vt_proc_alive(sc->old_scp);
2339 vt_proc_alive(sc->new_scp);
2341 /* wait for the controlling process to release the screen, if necessary */
2342 if (signal_vt_rel(sc->old_scp)) {
2347 /* go set up the new vty screen */
2352 /* wake up processes waiting for this vty */
2354 wakeup(VTY_WCHAN(sc,next_scr));
2356 /* wait for the controlling process to acknowledge, if necessary */
2357 if (signal_vt_acq(sc->cur_scp)) {
2362 sc->switch_in_progress = 0;
2363 if (sc->unit == sc_console_unit)
2364 cnavailable(sc_consptr, TRUE);
2366 DPRINTF(5, ("switch done\n"));
2372 do_switch_scr(sc_softc_t *sc, int s)
2374 vt_proc_alive(sc->new_scp);
2379 /* sc->cur_scp == sc->new_scp */
2380 wakeup(VTY_WCHAN(sc,sc->cur_scp->index));
2382 /* wait for the controlling process to acknowledge, if necessary */
2383 if (!signal_vt_acq(sc->cur_scp)) {
2384 sc->switch_in_progress = 0;
2385 if (sc->unit == sc_console_unit)
2386 cnavailable(sc_consptr, TRUE);
2393 vt_proc_alive(scr_stat *scp)
2398 if ((p = pfind(scp->pid)) != NULL)
2403 scp->smode.mode = VT_AUTO;
2404 DPRINTF(5, ("vt controlling process %d died\n", scp->pid));
2410 signal_vt_rel(scr_stat *scp)
2412 if (scp->smode.mode != VT_PROCESS)
2414 scp->status |= SWITCH_WAIT_REL;
2415 PROC_LOCK(scp->proc);
2416 psignal(scp->proc, scp->smode.relsig);
2417 PROC_UNLOCK(scp->proc);
2418 DPRINTF(5, ("sending relsig to %d\n", scp->pid));
2423 signal_vt_acq(scr_stat *scp)
2425 if (scp->smode.mode != VT_PROCESS)
2427 if (scp->sc->unit == sc_console_unit)
2428 cnavailable(sc_consptr, FALSE);
2429 scp->status |= SWITCH_WAIT_ACQ;
2430 PROC_LOCK(scp->proc);
2431 psignal(scp->proc, scp->smode.acqsig);
2432 PROC_UNLOCK(scp->proc);
2433 DPRINTF(5, ("sending acqsig to %d\n", scp->pid));
2438 finish_vt_rel(scr_stat *scp, int release, int *s)
2440 if (scp == scp->sc->old_scp && scp->status & SWITCH_WAIT_REL) {
2441 scp->status &= ~SWITCH_WAIT_REL;
2443 *s = do_switch_scr(scp->sc, *s);
2445 scp->sc->switch_in_progress = 0;
2452 finish_vt_acq(scr_stat *scp)
2454 if (scp == scp->sc->new_scp && scp->status & SWITCH_WAIT_ACQ) {
2455 scp->status &= ~SWITCH_WAIT_ACQ;
2456 scp->sc->switch_in_progress = 0;
2463 exchange_scr(sc_softc_t *sc)
2467 /* save the current state of video and keyboard */
2468 sc_move_cursor(sc->old_scp, sc->old_scp->xpos, sc->old_scp->ypos);
2469 if (!ISGRAPHSC(sc->old_scp))
2470 sc_remove_cursor_image(sc->old_scp);
2471 if (sc->old_scp->kbd_mode == K_XLATE)
2472 save_kbd_state(sc->old_scp);
2474 /* set up the video for the new screen */
2475 scp = sc->cur_scp = sc->new_scp;
2477 if (sc->old_scp->mode != scp->mode || ISUNKNOWNSC(sc->old_scp) || ISUNKNOWNSC(sc->new_scp))
2479 if (sc->old_scp->mode != scp->mode || ISUNKNOWNSC(sc->old_scp))
2484 sc_vtb_init(&scp->scr, VTB_FRAMEBUFFER, scp->xsize, scp->ysize,
2485 (void *)sc->adp->va_window, FALSE);
2487 scp->status |= MOUSE_HIDDEN;
2488 sc_move_cursor(scp, scp->xpos, scp->ypos);
2489 if (!ISGRAPHSC(scp))
2490 sc_set_cursor_image(scp);
2491 #ifndef SC_NO_PALETTE_LOADING
2492 if (ISGRAPHSC(sc->old_scp))
2493 load_palette(sc->adp, sc->palette);
2495 sc_set_border(scp, scp->border);
2497 /* set up the keyboard for the new screen */
2498 if (sc->old_scp->kbd_mode != scp->kbd_mode)
2499 kbd_ioctl(sc->kbd, KDSKBMODE, (caddr_t)&scp->kbd_mode);
2500 update_kbd_state(scp, scp->status, LOCK_MASK);
2506 sc_puts(scr_stat *scp, u_char *buf, int len)
2508 int need_unlock = 0;
2511 /* make screensaver happy */
2512 if (!sticky_splash && scp == scp->sc->cur_scp && !sc_saver_keyb_only)
2513 run_scrn_saver = FALSE;
2517 if (!kdb_active && !mtx_owned(&scp->scr_lock)) {
2519 mtx_lock_spin(&scp->scr_lock);
2521 (*scp->tsw->te_puts)(scp, buf, len);
2523 mtx_unlock_spin(&scp->scr_lock);
2526 if (scp->sc->delayed_next_scr)
2527 sc_switch_scr(scp->sc, scp->sc->delayed_next_scr - 1);
2531 sc_draw_cursor_image(scr_stat *scp)
2533 /* assert(scp == scp->sc->cur_scp); */
2534 SC_VIDEO_LOCK(scp->sc);
2535 (*scp->rndr->draw_cursor)(scp, scp->cursor_pos,
2536 scp->curs_attr.flags & CONS_BLINK_CURSOR, TRUE,
2537 sc_inside_cutmark(scp, scp->cursor_pos));
2538 scp->cursor_oldpos = scp->cursor_pos;
2539 SC_VIDEO_UNLOCK(scp->sc);
2543 sc_remove_cursor_image(scr_stat *scp)
2545 /* assert(scp == scp->sc->cur_scp); */
2546 SC_VIDEO_LOCK(scp->sc);
2547 (*scp->rndr->draw_cursor)(scp, scp->cursor_oldpos,
2548 scp->curs_attr.flags & CONS_BLINK_CURSOR, FALSE,
2549 sc_inside_cutmark(scp, scp->cursor_oldpos));
2550 SC_VIDEO_UNLOCK(scp->sc);
2554 update_cursor_image(scr_stat *scp)
2556 /* assert(scp == scp->sc->cur_scp); */
2557 sc_remove_cursor_image(scp);
2558 sc_set_cursor_image(scp);
2559 sc_draw_cursor_image(scp);
2563 sc_set_cursor_image(scr_stat *scp)
2565 scp->curs_attr.flags = scp->curr_curs_attr.flags;
2566 if (scp->curs_attr.flags & CONS_HIDDEN_CURSOR) {
2567 /* hidden cursor is internally represented as zero-height underline */
2568 scp->curs_attr.flags = CONS_CHAR_CURSOR;
2569 scp->curs_attr.base = scp->curs_attr.height = 0;
2570 } else if (scp->curs_attr.flags & CONS_CHAR_CURSOR) {
2571 scp->curs_attr.base = imin(scp->curr_curs_attr.base,
2572 scp->font_size - 1);
2573 scp->curs_attr.height = imin(scp->curr_curs_attr.height,
2574 scp->font_size - scp->curs_attr.base);
2575 } else { /* block cursor */
2576 scp->curs_attr.base = 0;
2577 scp->curs_attr.height = scp->font_size;
2580 /* assert(scp == scp->sc->cur_scp); */
2581 SC_VIDEO_LOCK(scp->sc);
2582 (*scp->rndr->set_cursor)(scp, scp->curs_attr.base, scp->curs_attr.height,
2583 scp->curs_attr.flags & CONS_BLINK_CURSOR);
2584 SC_VIDEO_UNLOCK(scp->sc);
2588 change_cursor_shape(scr_stat *scp, int flags, int base, int height)
2590 if ((scp == scp->sc->cur_scp) && !ISGRAPHSC(scp))
2591 sc_remove_cursor_image(scp);
2594 scp->curr_curs_attr.base = base;
2596 scp->curr_curs_attr.height = height;
2597 if (flags & CONS_RESET_CURSOR)
2598 scp->curr_curs_attr = scp->dflt_curs_attr;
2600 scp->curr_curs_attr.flags = flags & CONS_CURSOR_ATTRS;
2602 if ((scp == scp->sc->cur_scp) && !ISGRAPHSC(scp)) {
2603 sc_set_cursor_image(scp);
2604 sc_draw_cursor_image(scp);
2609 sc_change_cursor_shape(scr_stat *scp, int flags, int base, int height)
2617 if ((flags != -1) && (flags & CONS_LOCAL_CURSOR)) {
2618 /* local (per vty) change */
2619 change_cursor_shape(scp, flags, base, height);
2627 sc->curs_attr.base = base;
2629 sc->curs_attr.height = height;
2631 if (flags & CONS_RESET_CURSOR)
2632 sc->curs_attr = sc->dflt_curs_attr;
2634 sc->curs_attr.flags = flags & CONS_CURSOR_ATTRS;
2637 for (i = sc->first_vty; i < sc->first_vty + sc->vtys; ++i) {
2638 if ((dev = SC_DEV(sc, i)) == NULL)
2640 if ((scp = sc_get_stat(dev)) == NULL)
2642 scp->dflt_curs_attr = sc->curs_attr;
2643 change_cursor_shape(scp, CONS_RESET_CURSOR, -1, -1);
2649 scinit(int unit, int flags)
2653 * When syscons is being initialized as the kernel console, malloc()
2654 * is not yet functional, because various kernel structures has not been
2655 * fully initialized yet. Therefore, we need to declare the following
2656 * static buffers for the console. This is less than ideal,
2657 * but is necessry evil for the time being. XXX
2660 static u_short sc_buffer[ROW*COL*2];/* XXX */
2662 static u_short sc_buffer[ROW*COL]; /* XXX */
2664 #ifndef SC_NO_FONT_LOADING
2665 static u_char font_8[256*8];
2666 static u_char font_14[256*14];
2667 static u_char font_16[256*16];
2672 video_adapter_t *adp;
2677 /* one time initialization */
2678 if (init_done == COLD)
2679 sc_get_bios_values(&bios_value);
2683 * Allocate resources. Even if we are being called for the second
2684 * time, we must allocate them again, because they might have
2687 sc = sc_get_softc(unit, flags & SC_KERNEL_CONSOLE);
2688 if ((sc->flags & SC_INIT_DONE) == 0)
2689 SC_VIDEO_LOCKINIT(sc);
2692 if (sc->adapter >= 0) {
2693 vid_release(sc->adp, (void *)&sc->adapter);
2697 if (sc->keyboard >= 0) {
2698 DPRINTF(5, ("sc%d: releasing kbd%d\n", unit, sc->keyboard));
2699 i = kbd_release(sc->kbd, (void *)&sc->keyboard);
2700 DPRINTF(5, ("sc%d: kbd_release returned %d\n", unit, i));
2701 if (sc->kbd != NULL) {
2702 DPRINTF(5, ("sc%d: kbd != NULL!, index:%d, unit:%d, flags:0x%x\n",
2703 unit, sc->kbd->kb_index, sc->kbd->kb_unit, sc->kbd->kb_flags));
2707 sc->adapter = vid_allocate("*", unit, (void *)&sc->adapter);
2708 sc->adp = vid_get_adapter(sc->adapter);
2709 /* assert((sc->adapter >= 0) && (sc->adp != NULL)) */
2711 sc->keyboard = sc_allocate_keyboard(sc, unit);
2712 DPRINTF(1, ("sc%d: keyboard %d\n", unit, sc->keyboard));
2714 sc->kbd = kbd_get_keyboard(sc->keyboard);
2715 if (sc->kbd != NULL) {
2716 DPRINTF(1, ("sc%d: kbd index:%d, unit:%d, flags:0x%x\n",
2717 unit, sc->kbd->kb_index, sc->kbd->kb_unit, sc->kbd->kb_flags));
2720 if (!(sc->flags & SC_INIT_DONE) || (adp != sc->adp)) {
2722 sc->initial_mode = sc->adp->va_initial_mode;
2724 #ifndef SC_NO_FONT_LOADING
2725 if (flags & SC_KERNEL_CONSOLE) {
2726 sc->font_8 = font_8;
2727 sc->font_14 = font_14;
2728 sc->font_16 = font_16;
2729 } else if (sc->font_8 == NULL) {
2730 /* assert(sc_malloc) */
2731 sc->font_8 = malloc(sizeof(font_8), M_DEVBUF, M_WAITOK);
2732 sc->font_14 = malloc(sizeof(font_14), M_DEVBUF, M_WAITOK);
2733 sc->font_16 = malloc(sizeof(font_16), M_DEVBUF, M_WAITOK);
2737 /* extract the hardware cursor location and hide the cursor for now */
2738 (*vidsw[sc->adapter]->read_hw_cursor)(sc->adp, &col, &row);
2739 (*vidsw[sc->adapter]->set_hw_cursor)(sc->adp, -1, -1);
2741 /* set up the first console */
2742 sc->first_vty = unit*MAXCONS;
2743 sc->vtys = MAXCONS; /* XXX: should be configurable */
2744 if (flags & SC_KERNEL_CONSOLE) {
2746 * Set up devs structure but don't use it yet, calling make_dev()
2747 * might panic kernel. Wait for sc_attach_unit() to actually
2748 * create the devices.
2750 sc->dev = main_devs;
2751 scp = &main_console;
2752 init_scp(sc, sc->first_vty, scp);
2753 sc_vtb_init(&scp->vtb, VTB_MEMORY, scp->xsize, scp->ysize,
2754 (void *)sc_buffer, FALSE);
2755 if (sc_init_emulator(scp, SC_DFLT_TERM))
2756 sc_init_emulator(scp, "*");
2757 (*scp->tsw->te_default_attr)(scp,
2758 kernel_default.std_color,
2759 kernel_default.rev_color);
2761 /* assert(sc_malloc) */
2762 sc->dev = malloc(sizeof(struct cdev *)*sc->vtys, M_DEVBUF, M_WAITOK|M_ZERO);
2763 sc->dev[0] = make_dev(&sc_cdevsw, unit * MAXCONS,
2764 UID_ROOT, GID_WHEEL, 0600, "ttyv%r", unit * MAXCONS);
2765 sc_alloc_tty(sc->dev[0]);
2766 scp = alloc_scp(sc, sc->first_vty);
2767 SC_STAT(sc->dev[0]) = scp;
2772 /* copy screen to temporary buffer */
2773 sc_vtb_init(&scp->scr, VTB_FRAMEBUFFER, scp->xsize, scp->ysize,
2774 (void *)scp->sc->adp->va_window, FALSE);
2776 sc_vtb_copy(&scp->scr, 0, &scp->vtb, 0, scp->xsize*scp->ysize);
2779 /* move cursors to the initial positions */
2780 if (col >= scp->xsize)
2782 if (row >= scp->ysize)
2783 row = scp->ysize - 1;
2786 scp->cursor_pos = scp->cursor_oldpos = row*scp->xsize + col;
2788 if (bios_value.cursor_end < scp->font_size)
2789 sc->dflt_curs_attr.base = scp->font_size -
2790 bios_value.cursor_end - 1;
2792 sc->dflt_curs_attr.base = 0;
2793 i = bios_value.cursor_end - bios_value.cursor_start + 1;
2794 sc->dflt_curs_attr.height = imin(i, scp->font_size);
2795 sc->dflt_curs_attr.flags = 0;
2796 sc->curs_attr = sc->dflt_curs_attr;
2797 scp->curr_curs_attr = scp->dflt_curs_attr = sc->curs_attr;
2799 #ifndef SC_NO_SYSMOUSE
2800 sc_mouse_move(scp, scp->xpixel/2, scp->ypixel/2);
2802 if (!ISGRAPHSC(scp)) {
2803 sc_set_cursor_image(scp);
2804 sc_draw_cursor_image(scp);
2807 /* save font and palette */
2808 #ifndef SC_NO_FONT_LOADING
2809 sc->fonts_loaded = 0;
2810 if (ISFONTAVAIL(sc->adp->va_flags)) {
2812 bcopy(dflt_font_8, sc->font_8, sizeof(dflt_font_8));
2813 bcopy(dflt_font_14, sc->font_14, sizeof(dflt_font_14));
2814 bcopy(dflt_font_16, sc->font_16, sizeof(dflt_font_16));
2815 sc->fonts_loaded = FONT_16 | FONT_14 | FONT_8;
2816 if (scp->font_size < 14) {
2817 sc_load_font(scp, 0, 8, 8, sc->font_8, 0, 256);
2818 } else if (scp->font_size >= 16) {
2819 sc_load_font(scp, 0, 16, 8, sc->font_16, 0, 256);
2821 sc_load_font(scp, 0, 14, 8, sc->font_14, 0, 256);
2823 #else /* !SC_DFLT_FONT */
2824 if (scp->font_size < 14) {
2825 sc_save_font(scp, 0, 8, 8, sc->font_8, 0, 256);
2826 sc->fonts_loaded = FONT_8;
2827 } else if (scp->font_size >= 16) {
2828 sc_save_font(scp, 0, 16, 8, sc->font_16, 0, 256);
2829 sc->fonts_loaded = FONT_16;
2831 sc_save_font(scp, 0, 14, 8, sc->font_14, 0, 256);
2832 sc->fonts_loaded = FONT_14;
2834 #endif /* SC_DFLT_FONT */
2835 /* FONT KLUDGE: always use the font page #0. XXX */
2836 sc_show_font(scp, 0);
2838 #endif /* !SC_NO_FONT_LOADING */
2840 #ifndef SC_NO_PALETTE_LOADING
2841 save_palette(sc->adp, sc->palette);
2845 if (!(sc->flags & SC_SPLASH_SCRN)) {
2846 /* we are ready to put up the splash image! */
2847 splash_init(sc->adp, scsplash_callback, sc);
2848 sc->flags |= SC_SPLASH_SCRN;
2853 /* the rest is not necessary, if we have done it once */
2854 if (sc->flags & SC_INIT_DONE)
2857 /* initialize mapscrn arrays to a one to one map */
2858 for (i = 0; i < sizeof(sc->scr_map); i++)
2859 sc->scr_map[i] = sc->scr_rmap[i] = i;
2861 sc->scr_map[0x5c] = (u_char)0xfc; /* for backslash */
2864 sc->flags |= SC_INIT_DONE;
2868 scterm(int unit, int flags)
2873 sc = sc_get_softc(unit, flags & SC_KERNEL_CONSOLE);
2875 return; /* shouldn't happen */
2878 /* this console is no longer available for the splash screen */
2879 if (sc->flags & SC_SPLASH_SCRN) {
2880 splash_term(sc->adp);
2881 sc->flags &= ~SC_SPLASH_SCRN;
2886 /* move the hardware cursor to the upper-left corner */
2887 (*vidsw[sc->adapter]->set_hw_cursor)(sc->adp, 0, 0);
2890 /* release the keyboard and the video card */
2891 if (sc->keyboard >= 0)
2892 kbd_release(sc->kbd, &sc->keyboard);
2893 if (sc->adapter >= 0)
2894 vid_release(sc->adp, &sc->adapter);
2896 /* stop the terminal emulator, if any */
2897 scp = sc_get_stat(sc->dev[0]);
2899 (*scp->tsw->te_term)(scp, &scp->ts);
2900 if (scp->ts != NULL)
2901 free(scp->ts, M_DEVBUF);
2902 mtx_destroy(&scp->scr_lock);
2904 /* clear the structure */
2905 if (!(flags & SC_KERNEL_CONSOLE)) {
2906 /* XXX: We need delete_dev() for this */
2907 free(sc->dev, M_DEVBUF);
2909 /* XXX: We need a ttyunregister for this */
2910 free(sc->tty, M_DEVBUF);
2912 #ifndef SC_NO_FONT_LOADING
2913 free(sc->font_8, M_DEVBUF);
2914 free(sc->font_14, M_DEVBUF);
2915 free(sc->font_16, M_DEVBUF);
2917 /* XXX vtb, history */
2919 bzero(sc, sizeof(*sc));
2925 scshutdown(void *arg, int howto)
2927 /* assert(sc_console != NULL) */
2929 sc_touch_scrn_saver();
2930 if (!cold && sc_console
2931 && sc_console->sc->cur_scp->smode.mode == VT_AUTO
2932 && sc_console->smode.mode == VT_AUTO)
2933 sc_switch_scr(sc_console->sc, sc_console->index);
2934 shutdown_in_progress = TRUE;
2938 sc_clean_up(scr_stat *scp)
2944 if (scp->sc->flags & SC_SCRN_BLANKED) {
2945 sc_touch_scrn_saver();
2947 if ((error = wait_scrn_saver_stop(scp->sc)))
2951 scp->status |= MOUSE_HIDDEN;
2952 sc_remove_mouse_image(scp);
2953 sc_remove_cutmarking(scp);
2958 sc_alloc_scr_buffer(scr_stat *scp, int wait, int discard)
2964 sc_vtb_init(&new, VTB_MEMORY, scp->xsize, scp->ysize, NULL, wait);
2965 if (!discard && (old.vtb_flags & VTB_VALID)) {
2966 /* retain the current cursor position and buffer contants */
2967 scp->cursor_oldpos = scp->cursor_pos;
2969 * This works only if the old buffer has the same size as or larger
2970 * than the new one. XXX
2972 sc_vtb_copy(&old, 0, &new, 0, scp->xsize*scp->ysize);
2976 sc_vtb_destroy(&old);
2979 #ifndef SC_NO_SYSMOUSE
2980 /* move the mouse cursor at the center of the screen */
2981 sc_mouse_move(scp, scp->xpixel / 2, scp->ypixel / 2);
2986 *alloc_scp(sc_softc_t *sc, int vty)
2990 /* assert(sc_malloc) */
2992 scp = (scr_stat *)malloc(sizeof(scr_stat), M_DEVBUF, M_WAITOK);
2993 init_scp(sc, vty, scp);
2995 sc_alloc_scr_buffer(scp, TRUE, TRUE);
2996 if (sc_init_emulator(scp, SC_DFLT_TERM))
2997 sc_init_emulator(scp, "*");
2999 #ifndef SC_NO_CUTPASTE
3000 sc_alloc_cut_buffer(scp, TRUE);
3003 #ifndef SC_NO_HISTORY
3004 sc_alloc_history_buffer(scp, 0, 0, TRUE);
3011 init_scp(sc_softc_t *sc, int vty, scr_stat *scp)
3015 bzero(scp, sizeof(*scp));
3020 scp->mode = sc->initial_mode;
3021 (*vidsw[sc->adapter]->get_info)(sc->adp, scp->mode, &info);
3022 if (info.vi_flags & V_INFO_GRAPHICS) {
3023 scp->status |= GRAPHICS_MODE;
3024 scp->xpixel = info.vi_width;
3025 scp->ypixel = info.vi_height;
3026 scp->xsize = info.vi_width/info.vi_cwidth;
3027 scp->ysize = info.vi_height/info.vi_cheight;
3031 scp->xsize = info.vi_width;
3032 scp->ysize = info.vi_height;
3033 scp->xpixel = scp->xsize*info.vi_cwidth;
3034 scp->ypixel = scp->ysize*info.vi_cheight;
3035 scp->font_size = info.vi_cheight;
3036 scp->font_width = info.vi_cwidth;
3037 if (info.vi_cheight < 14) {
3038 #ifndef SC_NO_FONT_LOADING
3039 scp->font = sc->font_8;
3043 } else if (info.vi_cheight >= 16) {
3044 #ifndef SC_NO_FONT_LOADING
3045 scp->font = sc->font_16;
3050 #ifndef SC_NO_FONT_LOADING
3051 scp->font = sc->font_14;
3057 sc_vtb_init(&scp->vtb, VTB_MEMORY, 0, 0, NULL, FALSE);
3059 sc_vtb_init(&scp->scr, VTB_FRAMEBUFFER, 0, 0, NULL, FALSE);
3061 scp->xoff = scp->yoff = 0;
3062 scp->xpos = scp->ypos = 0;
3063 scp->start = scp->xsize * scp->ysize - 1;
3068 scp->border = (SC_NORM_ATTR >> 4) & 0x0f;
3069 scp->curr_curs_attr = scp->dflt_curs_attr = sc->curs_attr;
3070 scp->mouse_cut_start = scp->xsize*scp->ysize;
3071 scp->mouse_cut_end = -1;
3072 scp->mouse_signal = 0;
3074 scp->mouse_proc = NULL;
3075 scp->kbd_mode = K_XLATE;
3076 scp->bell_pitch = bios_value.bell_pitch;
3077 scp->bell_duration = BELL_DURATION;
3078 scp->status |= (bios_value.shift_state & NLKED);
3079 scp->status |= CURSOR_ENABLED | MOUSE_HIDDEN;
3082 scp->smode.mode = VT_AUTO;
3083 scp->history = NULL;
3084 scp->history_pos = 0;
3085 scp->history_size = 0;
3087 mtx_init(&scp->scr_lock, "scrlock", NULL, MTX_SPIN);
3091 sc_init_emulator(scr_stat *scp, char *name)
3098 if (name == NULL) /* if no name is given, use the current emulator */
3100 else /* ...otherwise find the named emulator */
3101 sw = sc_term_match(name);
3106 if (strcmp(sw->te_renderer, "*") != 0) {
3107 rndr = sc_render_match(scp, sw->te_renderer,
3108 scp->status & (GRAPHICS_MODE | PIXEL_MODE));
3111 rndr = sc_render_match(scp, scp->sc->adp->va_name,
3112 scp->status & (GRAPHICS_MODE | PIXEL_MODE));
3117 if (sw == scp->tsw) {
3118 error = (*sw->te_init)(scp, &scp->ts, SC_TE_WARM_INIT);
3120 scp->rndr->init(scp);
3121 sc_clear_screen(scp);
3122 /* assert(error == 0); */
3126 if (sc_malloc && (sw->te_size > 0))
3127 p = malloc(sw->te_size, M_DEVBUF, M_NOWAIT);
3130 error = (*sw->te_init)(scp, &p, SC_TE_COLD_INIT);
3135 (*scp->tsw->te_term)(scp, &scp->ts);
3136 if (scp->ts != NULL)
3137 free(scp->ts, M_DEVBUF);
3141 scp->rndr->init(scp);
3144 (*sw->te_default_attr)(scp, user_default.std_color, user_default.rev_color);
3145 sc_clear_screen(scp);
3151 * scgetc(flags) - get character from keyboard.
3152 * If flags & SCGETC_CN, then avoid harmful side effects.
3153 * If flags & SCGETC_NONBLOCK, then wait until a key is pressed, else
3154 * return NOKEY if there is nothing there.
3157 scgetc(sc_softc_t *sc, u_int flags)
3160 #ifndef SC_NO_HISTORY
3168 if (sc->kbd == NULL)
3173 /* I don't like this, but... XXX */
3174 if (flags & SCGETC_CN)
3175 sccnupdate(sc->cur_scp);
3178 /* first see if there is something in the keyboard port */
3180 c = kbd_read_char(sc->kbd, !(flags & SCGETC_NONBLOCK));
3182 if (!(flags & SCGETC_CN))
3183 sc_bell(scp, bios_value.bell_pitch, BELL_DURATION);
3184 } else if (c == NOKEY)
3190 /* make screensaver happy */
3192 sc_touch_scrn_saver();
3194 if (!(flags & SCGETC_CN))
3195 random_harvest(&c, sizeof(c), 1, 0, RANDOM_KEYBOARD);
3197 if (scp->kbd_mode != K_XLATE)
3200 /* if scroll-lock pressed allow history browsing */
3201 if (!ISGRAPHSC(scp) && scp->history && scp->status & SLKED) {
3203 scp->status &= ~CURSOR_ENABLED;
3204 sc_remove_cursor_image(scp);
3206 #ifndef SC_NO_HISTORY
3207 if (!(scp->status & BUFFER_SAVED)) {
3208 scp->status |= BUFFER_SAVED;
3212 /* FIXME: key codes */
3213 case SPCLKEY | FKEY | F(49): /* home key */
3214 sc_remove_cutmarking(scp);
3218 case SPCLKEY | FKEY | F(57): /* end key */
3219 sc_remove_cutmarking(scp);
3223 case SPCLKEY | FKEY | F(50): /* up arrow key */
3224 sc_remove_cutmarking(scp);
3225 if (sc_hist_up_line(scp))
3226 if (!(flags & SCGETC_CN))
3227 sc_bell(scp, bios_value.bell_pitch, BELL_DURATION);
3230 case SPCLKEY | FKEY | F(58): /* down arrow key */
3231 sc_remove_cutmarking(scp);
3232 if (sc_hist_down_line(scp))
3233 if (!(flags & SCGETC_CN))
3234 sc_bell(scp, bios_value.bell_pitch, BELL_DURATION);
3237 case SPCLKEY | FKEY | F(51): /* page up key */
3238 sc_remove_cutmarking(scp);
3239 for (i=0; i<scp->ysize; i++)
3240 if (sc_hist_up_line(scp)) {
3241 if (!(flags & SCGETC_CN))
3242 sc_bell(scp, bios_value.bell_pitch, BELL_DURATION);
3247 case SPCLKEY | FKEY | F(59): /* page down key */
3248 sc_remove_cutmarking(scp);
3249 for (i=0; i<scp->ysize; i++)
3250 if (sc_hist_down_line(scp)) {
3251 if (!(flags & SCGETC_CN))
3252 sc_bell(scp, bios_value.bell_pitch, BELL_DURATION);
3257 #endif /* SC_NO_HISTORY */
3261 * Process and consume special keys here. Return a plain char code
3262 * or a char code with the META flag or a function key code.
3266 /* goto next_code */
3271 switch (KEYCHAR(c)) {
3273 case NLK: case CLK: case ALK:
3276 kbd_ioctl(sc->kbd, KDGKBSTATE, (caddr_t)&f);
3278 scp->status |= SLKED;
3280 if (scp->status & SLKED) {
3281 scp->status &= ~SLKED;
3282 #ifndef SC_NO_HISTORY
3283 if (scp->status & BUFFER_SAVED) {
3284 if (!sc_hist_restore(scp))
3285 sc_remove_cutmarking(scp);
3286 scp->status &= ~BUFFER_SAVED;
3287 scp->status |= CURSOR_ENABLED;
3288 sc_draw_cursor_image(scp);
3290 tp = VIRTUAL_TTY(sc, scp->index);
3299 #ifndef SC_NO_CUTPASTE
3300 sc_mouse_paste(scp);
3304 /* NON-LOCKING KEYS */
3306 case LSH: case RSH: case LCTR: case RCTR:
3307 case LALT: case RALT: case ASH: case META:
3311 if (!(sc->flags & SC_SCRN_BLANKED))
3317 /* force activatation/deactivation of the screen saver */
3318 if (!(sc->flags & SC_SCRN_BLANKED)) {
3319 run_scrn_saver = TRUE;
3320 sc->scrn_time_stamp -= scrn_blank_time;
3324 * While devices are being probed, the screen saver need
3325 * to be invoked explictly. XXX
3327 if (sc->flags & SC_SCRN_BLANKED) {
3328 scsplash_stick(FALSE);
3329 stop_scrn_saver(sc, current_saver);
3331 if (!ISGRAPHSC(scp)) {
3332 scsplash_stick(TRUE);
3333 (*current_saver)(sc, TRUE);
3337 #endif /* DEV_SPLASH */
3341 #ifndef SC_DISABLE_REBOOT
3348 #ifndef SC_DISABLE_REBOOT
3350 shutdown_nice(RB_HALT);
3355 #ifndef SC_DISABLE_REBOOT
3357 shutdown_nice(RB_HALT|RB_POWEROFF);
3362 power_pm_suspend(POWER_SLEEP_STATE_SUSPEND);
3365 power_pm_suspend(POWER_SLEEP_STATE_STANDBY);
3369 #ifndef SC_DISABLE_KDBKEY
3371 kdb_enter_why(KDB_WHY_BREAK,
3372 "manual escape to debugger");
3377 if (enable_panic_key)
3378 panic("Forced by the panic key");
3382 this_scr = scp->index;
3383 for (i = (this_scr - sc->first_vty + 1)%sc->vtys;
3384 sc->first_vty + i != this_scr;
3385 i = (i + 1)%sc->vtys) {
3386 struct tty *tp = VIRTUAL_TTY(sc, sc->first_vty + i);
3387 if (ISTTYOPEN(tp)) {
3388 sc_switch_scr(scp->sc, sc->first_vty + i);
3395 this_scr = scp->index;
3396 for (i = (this_scr - sc->first_vty + sc->vtys - 1)%sc->vtys;
3397 sc->first_vty + i != this_scr;
3398 i = (i + sc->vtys - 1)%sc->vtys) {
3399 struct tty *tp = VIRTUAL_TTY(sc, sc->first_vty + i);
3400 if (ISTTYOPEN(tp)) {
3401 sc_switch_scr(scp->sc, sc->first_vty + i);
3408 if (KEYCHAR(c) >= F_SCR && KEYCHAR(c) <= L_SCR) {
3409 sc_switch_scr(scp->sc, sc->first_vty + KEYCHAR(c) - F_SCR);
3412 /* assert(c & FKEY) */
3413 if (!(sc->flags & SC_SCRN_BLANKED))
3417 /* goto next_code */
3419 /* regular keys (maybe MKEY is set) */
3420 if (!(sc->flags & SC_SCRN_BLANKED))
3429 scmmap(struct cdev *dev, vm_offset_t offset, vm_paddr_t *paddr, int nprot)
3433 scp = sc_get_stat(dev);
3434 if (scp != scp->sc->cur_scp)
3436 return (*vidsw[scp->sc->adapter]->mmap)(scp->sc->adp, offset, paddr, nprot);
3440 save_kbd_state(scr_stat *scp)
3445 error = kbd_ioctl(scp->sc->kbd, KDGKBSTATE, (caddr_t)&state);
3446 if (error == ENOIOCTL)
3449 scp->status &= ~LOCK_MASK;
3450 scp->status |= state;
3456 update_kbd_state(scr_stat *scp, int new_bits, int mask)
3461 if (mask != LOCK_MASK) {
3462 error = kbd_ioctl(scp->sc->kbd, KDGKBSTATE, (caddr_t)&state);
3463 if (error == ENOIOCTL)
3468 state |= new_bits & mask;
3470 state = new_bits & LOCK_MASK;
3472 error = kbd_ioctl(scp->sc->kbd, KDSKBSTATE, (caddr_t)&state);
3473 if (error == ENOIOCTL)
3479 update_kbd_leds(scr_stat *scp, int which)
3484 error = kbd_ioctl(scp->sc->kbd, KDSETLED, (caddr_t)&which);
3485 if (error == ENOIOCTL)
3491 set_mode(scr_stat *scp)
3495 /* reject unsupported mode */
3496 if ((*vidsw[scp->sc->adapter]->get_info)(scp->sc->adp, scp->mode, &info))
3499 /* if this vty is not currently showing, do nothing */
3500 if (scp != scp->sc->cur_scp)
3503 /* setup video hardware for the given mode */
3504 (*vidsw[scp->sc->adapter]->set_mode)(scp->sc->adp, scp->mode);
3505 scp->rndr->init(scp);
3507 sc_vtb_init(&scp->scr, VTB_FRAMEBUFFER, scp->xsize, scp->ysize,
3508 (void *)scp->sc->adp->va_window, FALSE);
3511 #ifndef SC_NO_FONT_LOADING
3512 /* load appropriate font */
3513 if (!(scp->status & GRAPHICS_MODE)) {
3514 if (!(scp->status & PIXEL_MODE) && ISFONTAVAIL(scp->sc->adp->va_flags)) {
3515 if (scp->font_size < 14) {
3516 if (scp->sc->fonts_loaded & FONT_8)
3517 sc_load_font(scp, 0, 8, 8, scp->sc->font_8, 0, 256);
3518 } else if (scp->font_size >= 16) {
3519 if (scp->sc->fonts_loaded & FONT_16)
3520 sc_load_font(scp, 0, 16, 8, scp->sc->font_16, 0, 256);
3522 if (scp->sc->fonts_loaded & FONT_14)
3523 sc_load_font(scp, 0, 14, 8, scp->sc->font_14, 0, 256);
3527 * This is an interim kludge to display correct font.
3528 * Always use the font page #0 on the video plane 2.
3529 * Somehow we cannot show the font in other font pages on
3530 * some video cards... XXX
3532 sc_show_font(scp, 0);
3536 #endif /* !SC_NO_FONT_LOADING */
3538 sc_set_border(scp, scp->border);
3539 sc_set_cursor_image(scp);
3545 sc_set_border(scr_stat *scp, int color)
3547 SC_VIDEO_LOCK(scp->sc);
3548 (*scp->rndr->draw_border)(scp, color);
3549 SC_VIDEO_UNLOCK(scp->sc);
3552 #ifndef SC_NO_FONT_LOADING
3554 sc_load_font(scr_stat *scp, int page, int size, int width, u_char *buf,
3555 int base, int count)
3560 sc->font_loading_in_progress = TRUE;
3561 (*vidsw[sc->adapter]->load_font)(sc->adp, page, size, width, buf, base,
3563 sc->font_loading_in_progress = FALSE;
3567 sc_save_font(scr_stat *scp, int page, int size, int width, u_char *buf,
3568 int base, int count)
3573 sc->font_loading_in_progress = TRUE;
3574 (*vidsw[sc->adapter]->save_font)(sc->adp, page, size, width, buf, base,
3576 sc->font_loading_in_progress = FALSE;
3580 sc_show_font(scr_stat *scp, int page)
3582 (*vidsw[scp->sc->adapter]->show_font)(scp->sc->adp, page);
3584 #endif /* !SC_NO_FONT_LOADING */
3587 sc_paste(scr_stat *scp, u_char *p, int count)
3592 tp = VIRTUAL_TTY(scp->sc, scp->sc->cur_scp->index);
3595 rmap = scp->sc->scr_rmap;
3596 for (; count > 0; --count)
3597 ttyld_rint(tp, rmap[*p++]);
3601 sc_bell(scr_stat *scp, int pitch, int duration)
3603 if (cold || shutdown_in_progress || !enable_bell)
3606 if (scp != scp->sc->cur_scp && (scp->sc->flags & SC_QUIET_BELL))
3609 if (scp->sc->flags & SC_VISUAL_BELL) {
3610 if (scp->sc->blink_in_progress)
3612 scp->sc->blink_in_progress = 3;
3613 if (scp != scp->sc->cur_scp)
3614 scp->sc->blink_in_progress += 2;
3615 blink_screen(scp->sc->cur_scp);
3616 } else if (duration != 0 && pitch != 0) {
3617 if (scp != scp->sc->cur_scp)
3619 sysbeep(pitch, duration);
3624 blink_screen(void *arg)
3626 scr_stat *scp = arg;
3629 if (ISGRAPHSC(scp) || (scp->sc->blink_in_progress <= 1)) {
3630 scp->sc->blink_in_progress = 0;
3632 tp = VIRTUAL_TTY(scp->sc, scp->index);
3635 if (scp->sc->delayed_next_scr)
3636 sc_switch_scr(scp->sc, scp->sc->delayed_next_scr - 1);
3639 (*scp->rndr->draw)(scp, 0, scp->xsize*scp->ysize,
3640 scp->sc->blink_in_progress & 1);
3641 scp->sc->blink_in_progress--;
3642 timeout(blink_screen, scp, hz / 10);
3647 * Until sc_attach_unit() gets called no dev structures will be available
3648 * to store the per-screen current status. This is the case when the
3649 * kernel is initially booting and needs access to its console. During
3650 * this early phase of booting the console's current status is kept in
3651 * one statically defined scr_stat structure, and any pointers to the
3652 * dev structures will be NULL.
3656 sc_get_stat(struct cdev *devptr)
3659 return (&main_console);
3660 return (SC_STAT(devptr));
3664 * Allocate active keyboard. Try to allocate "kbdmux" keyboard first, and,
3665 * if found, add all non-busy keyboards to "kbdmux". Otherwise look for
3670 sc_allocate_keyboard(sc_softc_t *sc, int unit)
3676 idx0 = kbd_allocate("kbdmux", -1, (void *)&sc->keyboard, sckbdevent, sc);
3678 k0 = kbd_get_keyboard(idx0);
3680 for (idx = kbd_find_keyboard2("*", -1, 0);
3682 idx = kbd_find_keyboard2("*", -1, idx + 1)) {
3683 k = kbd_get_keyboard(idx);
3685 if (idx == idx0 || KBD_IS_BUSY(k))
3688 bzero(&ki, sizeof(ki));
3689 strcpy(ki.kb_name, k->kb_name);
3690 ki.kb_unit = k->kb_unit;
3692 kbd_ioctl(k0, KBADDKBD, (caddr_t) &ki);
3695 idx0 = kbd_allocate("*", unit, (void *)&sc->keyboard, sckbdevent, sc);