2 * Copyright (c) 1992-1998 Søren Schmidt
5 * This code is derived from software contributed to The DragonFly Project
6 * by Sascha Wildner <saw@online.de>
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
11 * 1. Redistributions of source code must retain the above copyright
12 * notice, this list of conditions and the following disclaimer,
13 * without modification, immediately at the beginning of the file.
14 * 2. Redistributions in binary form must reproduce the above copyright
15 * notice, this list of conditions and the following disclaimer in the
16 * documentation and/or other materials provided with the distribution.
17 * 3. The name of the author may not be used to endorse or promote products
18 * derived from this software without specific prior written permission.
20 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
21 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
22 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
23 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
24 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
25 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
26 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
27 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
28 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
29 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31 * $FreeBSD: /usr/local/www/cvsroot/FreeBSD/src/sys/dev/syscons/syscons.c,v 1.336.2.17 2004/03/25 08:41:09 ru Exp $
32 * $DragonFly: src/sys/dev/misc/syscons/syscons.c,v 1.23 2005/10/30 10:07:10 swildner Exp $
35 #include "use_splash.h"
36 #include "opt_syscons.h"
40 #include <sys/param.h>
41 #include <sys/systm.h>
42 #include <sys/eventhandler.h>
43 #include <sys/reboot.h>
46 #include <sys/signalvar.h>
47 #include <sys/sysctl.h>
49 #include <sys/kernel.h>
51 #include <sys/random.h>
52 #include <sys/thread2.h>
54 #include <machine/clock.h>
55 #include <machine/console.h>
56 #include <machine/psl.h>
57 #include <machine/pc/display.h>
58 #include <machine/apm_bios.h>
59 #include <machine/frame.h>
61 #include <dev/misc/kbd/kbdreg.h>
62 #include <dev/video/fb/fbreg.h>
63 #include <dev/video/fb/splashreg.h>
69 #define DEFAULT_BLANKTIME (5*60) /* 5 minutes */
70 #define MAX_BLANKTIME (7*24*60*60) /* 7 days!? */
72 #define KEYCODE_BS 0x0e /* "<-- Backspace" key, XXX */
74 MALLOC_DEFINE(M_SYSCONS, "syscons", "Syscons");
76 typedef struct default_attr {
77 int std_color; /* normal hardware color */
78 int rev_color; /* reverse hardware color */
81 static default_attr user_default = {
86 static default_attr kernel_default = {
88 SC_KERNEL_CONS_REV_ATTR,
91 static int sc_console_unit = -1;
92 static scr_stat *sc_console;
93 static struct tty *sc_console_tty;
94 static void *kernel_console_ts;
96 static char init_done = COLD;
97 static char shutdown_in_progress = FALSE;
98 static char sc_malloc = FALSE;
100 static int saver_mode = CONS_NO_SAVER; /* LKM/user saver */
101 static int run_scrn_saver = FALSE; /* should run the saver? */
102 static long scrn_blank_time = 0; /* screen saver timeout value */
104 static int scrn_blanked; /* # of blanked screen */
105 static int sticky_splash = FALSE;
107 static void none_saver(sc_softc_t *sc, int blank) { }
108 static void (*current_saver)(sc_softc_t *, int) = none_saver;
111 #if !defined(SC_NO_FONT_LOADING) && defined(SC_DFLT_FONT)
115 d_ioctl_t *sc_user_ioctl;
117 static bios_values_t bios_value;
119 static int enable_panic_key;
120 SYSCTL_INT(_machdep, OID_AUTO, enable_panic_key, CTLFLAG_RW, &enable_panic_key,
123 #define SC_CONSOLECTL 255
125 #define VIRTUAL_TTY(sc, x) (SC_DEV((sc), (x)) != NULL ? \
126 SC_DEV((sc), (x))->si_tty : NULL)
127 #define ISTTYOPEN(tp) ((tp) && ((tp)->t_state & TS_ISOPEN))
132 static int scvidprobe(int unit, int flags, int cons);
133 static int sckbdprobe(int unit, int flags, int cons);
134 static void scmeminit(void *arg);
135 static int scdevtounit(dev_t dev);
136 static kbd_callback_func_t sckbdevent;
137 static int scparam(struct tty *tp, struct termios *t);
138 static void scstart(struct tty *tp);
139 static void scinit(int unit, int flags);
140 static void scterm(int unit, int flags);
141 static void scshutdown(void *arg, int howto);
142 static u_int scgetc(sc_softc_t *sc, u_int flags);
144 #define SCGETC_NONBLOCK 2
145 static int sccngetch(int flags);
146 static void sccnupdate(scr_stat *scp);
147 static scr_stat *alloc_scp(sc_softc_t *sc, int vty);
148 static void init_scp(sc_softc_t *sc, int vty, scr_stat *scp);
149 static timeout_t scrn_timer;
150 static int and_region(int *s1, int *e1, int s2, int e2);
151 static void scrn_update(scr_stat *scp, int show_cursor);
154 static int scsplash_callback(int event, void *arg);
155 static void scsplash_saver(sc_softc_t *sc, int show);
156 static int add_scrn_saver(void (*this_saver)(sc_softc_t *, int));
157 static int remove_scrn_saver(void (*this_saver)(sc_softc_t *, int));
158 static int set_scrn_saver_mode(scr_stat *scp, int mode, u_char *pal, int border);
159 static int restore_scrn_saver_mode(scr_stat *scp, int changemode);
160 static void stop_scrn_saver(sc_softc_t *sc, void (*saver)(sc_softc_t *, int));
161 static int wait_scrn_saver_stop(sc_softc_t *sc);
162 #define scsplash_stick(stick) (sticky_splash = (stick))
164 #define scsplash_stick(stick)
167 static void do_switch_scr(sc_softc_t *sc);
168 static int vt_proc_alive(scr_stat *scp);
169 static int signal_vt_rel(scr_stat *scp);
170 static int signal_vt_acq(scr_stat *scp);
171 static int finish_vt_rel(scr_stat *scp, int release);
172 static int finish_vt_acq(scr_stat *scp);
173 static void exchange_scr(sc_softc_t *sc);
174 static void update_cursor_image(scr_stat *scp);
175 static int save_kbd_state(scr_stat *scp);
176 static int update_kbd_state(scr_stat *scp, int state, int mask);
177 static int update_kbd_leds(scr_stat *scp, int which);
178 static timeout_t blink_screen;
180 #define CDEV_MAJOR 12
182 static cn_probe_t sccnprobe;
183 static cn_init_t sccninit;
184 static cn_getc_t sccngetc;
185 static cn_checkc_t sccncheckc;
186 static cn_putc_t sccnputc;
187 static cn_dbctl_t sccndbctl;
188 static cn_term_t sccnterm;
190 CONS_DRIVER(sc, sccnprobe, sccninit, sccnterm, sccngetc, sccncheckc, sccnputc,
193 static d_open_t scopen;
194 static d_close_t scclose;
195 static d_read_t scread;
196 static d_ioctl_t scioctl;
197 static d_mmap_t scmmap;
199 static struct cdevsw sc_cdevsw = {
201 /* maj */ CDEV_MAJOR,
202 /* flags */ D_TTY | D_KQFILTER,
209 /* write */ ttywrite,
213 /* strategy */ nostrategy,
216 /* kqfilter */ ttykqfilter
220 sc_probe_unit(int unit, int flags)
222 if (!scvidprobe(unit, flags, FALSE)) {
224 printf("sc%d: no video adapter found.\n", unit);
228 /* syscons will be attached even when there is no keyboard */
229 sckbdprobe(unit, flags, FALSE);
234 /* probe video adapters, return TRUE if found */
236 scvidprobe(int unit, int flags, int cons)
239 * Access the video adapter driver through the back door!
240 * Video adapter drivers need to be configured before syscons.
241 * However, when syscons is being probed as the low-level console,
242 * they have not been initialized yet. We force them to initialize
243 * themselves here. XXX
245 vid_configure(cons ? VIO_PROBE_ONLY : 0);
247 return (vid_find_adapter("*", unit) >= 0);
250 /* probe the keyboard, return TRUE if found */
252 sckbdprobe(int unit, int flags, int cons)
254 /* access the keyboard driver through the backdoor! */
255 kbd_configure(cons ? KB_CONF_PROBE_ONLY : 0);
257 return (kbd_find_keyboard("*", unit) >= 0);
261 adapter_name(video_adapter_t *adp)
267 { KD_MONO, { "MDA", "MDA" } },
268 { KD_HERCULES, { "Hercules", "Hercules" } },
269 { KD_CGA, { "CGA", "CGA" } },
270 { KD_EGA, { "EGA", "EGA (mono)" } },
271 { KD_VGA, { "VGA", "VGA (mono)" } },
272 { KD_TGA, { "TGA", "TGA" } },
273 { -1, { "Unknown", "Unknown" } },
277 for (i = 0; names[i].type != -1; ++i)
278 if (names[i].type == adp->va_type)
280 return names[i].name[(adp->va_flags & V_ADP_COLOR) ? 0 : 1];
284 sc_attach_unit(int unit, int flags)
294 flags &= ~SC_KERNEL_CONSOLE;
296 if (sc_console_unit == unit) {
298 * If this unit is being used as the system console, we need to
299 * adjust some variables and buffers before and after scinit().
301 /* assert(sc_console != NULL) */
302 flags |= SC_KERNEL_CONSOLE;
307 if (sc_console->tsw->te_size > 0) {
308 /* assert(sc_console->ts != NULL); */
309 kernel_console_ts = sc_console->ts;
310 sc_console->ts = malloc(sc_console->tsw->te_size,
311 M_SYSCONS, M_WAITOK);
312 bcopy(kernel_console_ts, sc_console->ts, sc_console->tsw->te_size);
313 (*sc_console->tsw->te_default_attr)(sc_console,
314 user_default.std_color,
315 user_default.rev_color);
321 sc = sc_get_softc(unit, flags & SC_KERNEL_CONSOLE);
323 callout_init(&sc->scrn_timer_ch);
324 scp = SC_STAT(sc->dev[0]);
325 if (sc_console == NULL) /* sc_console_unit < 0 */
329 if ((sc->config & SC_VESA800X600)
330 && ((*vidsw[sc->adapter]->get_info)(sc->adp, M_VESA_800x600, &info) == 0)) {
332 if (sc->flags & SC_SPLASH_SCRN)
333 splash_term(sc->adp);
335 sc_set_graphics_mode(scp, NULL, M_VESA_800x600);
336 sc_set_pixel_mode(scp, NULL, COL, ROW, 16);
337 sc->initial_mode = M_VESA_800x600;
339 /* put up the splash again! */
340 if (sc->flags & SC_SPLASH_SCRN)
341 splash_init(sc->adp, scsplash_callback, sc);
344 #endif /* SC_PIXEL_MODE */
346 /* initialize cursor */
348 update_cursor_image(scp);
350 /* get screen update going */
353 /* set up the keyboard */
354 kbd_ioctl(sc->kbd, KDSKBMODE, (caddr_t)&scp->kbd_mode);
355 update_kbd_state(scp, scp->status, LOCK_MASK);
357 printf("sc%d: %s <%d virtual consoles, flags=0x%x>\n",
358 unit, adapter_name(sc->adp), sc->vtys, sc->config);
360 printf("sc%d:", unit);
361 if (sc->adapter >= 0)
362 printf(" fb%d", sc->adapter);
363 if (sc->keyboard >= 0)
364 printf(", kbd%d", sc->keyboard);
366 printf(", terminal emulator: %s (%s)",
367 scp->tsw->te_name, scp->tsw->te_desc);
371 /* register a shutdown callback for the kernel console */
372 if (sc_console_unit == unit)
373 EVENTHANDLER_REGISTER(shutdown_pre_sync, scshutdown,
374 (void *)(uintptr_t)unit, SHUTDOWN_PRI_DEFAULT);
377 * create devices. cdevsw_add() must be called to make devices under
378 * this major number available to userland.
380 cdevsw_add(&sc_cdevsw, ~(MAXCONS - 1), unit * MAXCONS);
382 for (vc = 0; vc < sc->vtys; vc++) {
383 dev = make_dev(&sc_cdevsw, vc + unit * MAXCONS,
384 UID_ROOT, GID_WHEEL, 0600, "ttyv%r", vc + unit * MAXCONS);
387 * The first vty already has struct tty and scr_stat initialized
388 * in scinit(). The other vtys will have these structs when
393 cdevsw_add(&sc_cdevsw, -1, SC_CONSOLECTL); /* XXX */
394 dev = make_dev(&sc_cdevsw, SC_CONSOLECTL,
395 UID_ROOT, GID_WHEEL, 0600, "consolectl");
396 dev->si_tty = sc_console_tty = ttymalloc(sc_console_tty);
397 dev->si_drv1 = sc_console;
410 * As soon as malloc() becomes functional, we had better allocate
411 * various buffers for the kernel console.
414 if (sc_console_unit < 0) /* sc_console == NULL */
417 /* copy the temporary buffer to the final buffer */
418 sc_alloc_scr_buffer(sc_console, TRUE, FALSE);
420 #ifndef SC_NO_CUTPASTE
421 sc_alloc_cut_buffer(sc_console, TRUE);
424 #ifndef SC_NO_HISTORY
425 /* initialize history buffer & pointers */
426 sc_alloc_history_buffer(sc_console, 0, 0, TRUE);
431 SYSINIT(sc_mem, SI_SUB_KMEM, SI_ORDER_ANY, scmeminit, NULL);
434 scdevtounit(dev_t dev)
436 int vty = SC_VTY(dev);
438 if (vty == SC_CONSOLECTL)
439 return ((sc_console != NULL) ? sc_console->sc->unit : -1);
440 else if ((vty < 0) || (vty >= MAXCONS*sc_max_unit()))
447 scopen(dev_t dev, int flag, int mode, struct thread *td)
449 int unit = scdevtounit(dev);
456 DPRINTF(5, ("scopen: dev:%d,%d, unit:%d, vty:%d\n",
457 major(dev), minor(dev), unit, SC_VTY(dev)));
459 sc = sc_get_softc(unit, (sc_console_unit == unit) ? SC_KERNEL_CONSOLE : 0);
463 tp = dev->si_tty = ttymalloc(dev->si_tty);
464 tp->t_oproc = scstart;
465 tp->t_param = scparam;
466 tp->t_stop = nottystop;
468 if (!ISTTYOPEN(tp)) {
470 /* Use the current setting of the <-- key as default VERASE. */
471 /* If the Delete key is preferable, an stty is necessary */
472 if (sc->kbd != NULL) {
473 key.keynum = KEYCODE_BS;
474 kbd_ioctl(sc->kbd, GIO_KEYMAPENT, (caddr_t)&key);
475 tp->t_cc[VERASE] = key.key.map[0];
477 tp->t_iflag = TTYDEF_IFLAG;
478 tp->t_oflag = TTYDEF_OFLAG;
479 tp->t_cflag = TTYDEF_CFLAG;
480 tp->t_lflag = TTYDEF_LFLAG;
481 tp->t_ispeed = tp->t_ospeed = TTYDEF_SPEED;
482 scparam(tp, &tp->t_termios);
483 (*linesw[tp->t_line].l_modem)(tp, 1);
486 if (tp->t_state & TS_XCLUDE && suser(td))
489 error = (*linesw[tp->t_line].l_open)(dev, tp);
493 scp = dev->si_drv1 = alloc_scp(sc, SC_VTY(dev));
495 sc_set_pixel_mode(scp, NULL, COL, ROW, 16);
497 if (!tp->t_winsize.ws_col && !tp->t_winsize.ws_row) {
498 tp->t_winsize.ws_col = scp->xsize;
499 tp->t_winsize.ws_row = scp->ysize;
506 scclose(dev_t dev, int flag, int mode, struct thread *td)
508 struct tty *tp = dev->si_tty;
512 if (SC_VTY(dev) != SC_CONSOLECTL) {
513 scp = SC_STAT(tp->t_dev);
514 /* were we in the middle of the VT switching process? */
515 DPRINTF(5, ("sc%d: scclose(), ", scp->sc->unit));
516 if ((scp == scp->sc->cur_scp) && (scp->sc->unit == sc_console_unit))
517 cons_unavail = FALSE;
519 * note: must be called from a critical section because finish_vt_rel
520 * will call do_switch_scr which releases it temporarily
522 if (finish_vt_rel(scp, TRUE) == 0) /* force release */
523 DPRINTF(5, ("reset WAIT_REL, "));
524 if (finish_vt_acq(scp) == 0) /* force acknowledge */
525 DPRINTF(5, ("reset WAIT_ACQ, "));
527 if (scp == &main_console) {
530 scp->smode.mode = VT_AUTO;
533 sc_vtb_destroy(&scp->vtb);
534 sc_vtb_destroy(&scp->scr);
535 sc_free_history_buffer(scp, scp->ysize);
537 free(scp, M_SYSCONS);
542 scp->smode.mode = VT_AUTO;
544 scp->kbd_mode = K_XLATE;
545 if (scp == scp->sc->cur_scp)
546 kbd_ioctl(scp->sc->kbd, KDSKBMODE, (caddr_t)&scp->kbd_mode);
547 DPRINTF(5, ("done.\n"));
549 (*linesw[tp->t_line].l_close)(tp, flag);
556 scread(dev_t dev, struct uio *uio, int flag)
558 sc_touch_scrn_saver();
559 return ttyread(dev, uio, flag);
563 sckbdevent(keyboard_t *thiskbd, int event, void *arg)
571 sc = (sc_softc_t *)arg;
572 /* assert(thiskbd == sc->kbd) */
577 case KBDIO_UNLOADING:
580 kbd_release(thiskbd, (void *)&sc->keyboard);
587 * Loop while there is still input to get from the keyboard.
588 * I don't think this is nessesary, and it doesn't fix
589 * the Xaccel-2.1 keyboard hang, but it can't hurt. XXX
591 while ((c = scgetc(sc, SCGETC_NONBLOCK)) != NOKEY) {
593 cur_tty = VIRTUAL_TTY(sc, sc->cur_scp->index);
594 if (!ISTTYOPEN(cur_tty)) {
595 cur_tty = sc_console_tty;
596 if (!ISTTYOPEN(cur_tty))
600 if ((*sc->cur_scp->tsw->te_input)(sc->cur_scp, c, cur_tty))
603 switch (KEYFLAGS(c)) {
604 case 0x0000: /* normal key */
605 (*linesw[cur_tty->t_line].l_rint)(KEYCHAR(c), cur_tty);
607 case FKEY: /* function key, return string */
608 cp = kbd_get_fkeystr(thiskbd, KEYCHAR(c), &len);
611 (*linesw[cur_tty->t_line].l_rint)(*cp++, cur_tty);
614 case MKEY: /* meta is active, prepend ESC */
615 (*linesw[cur_tty->t_line].l_rint)(0x1b, cur_tty);
616 (*linesw[cur_tty->t_line].l_rint)(KEYCHAR(c), cur_tty);
618 case BKEY: /* backtab fixed sequence (esc [ Z) */
619 (*linesw[cur_tty->t_line].l_rint)(0x1b, cur_tty);
620 (*linesw[cur_tty->t_line].l_rint)('[', cur_tty);
621 (*linesw[cur_tty->t_line].l_rint)('Z', cur_tty);
626 sc->cur_scp->status |= MOUSE_HIDDEN;
632 scparam(struct tty *tp, struct termios *t)
634 tp->t_ispeed = t->c_ispeed;
635 tp->t_ospeed = t->c_ospeed;
636 tp->t_cflag = t->c_cflag;
641 scioctl(dev_t dev, u_long cmd, caddr_t data, int flag, struct thread *td)
648 struct proc *p = td->td_proc;
654 /* If there is a user_ioctl function call that first */
656 error = (*sc_user_ioctl)(dev, cmd, data, flag, td);
657 if (error != ENOIOCTL)
661 error = sc_vid_ioctl(tp, cmd, data, flag, td);
662 if (error != ENOIOCTL)
665 #ifndef SC_NO_HISTORY
666 error = sc_hist_ioctl(tp, cmd, data, flag, td);
667 if (error != ENOIOCTL)
671 #ifndef SC_NO_SYSMOUSE
672 error = sc_mouse_ioctl(tp, cmd, data, flag, td);
673 if (error != ENOIOCTL)
677 scp = SC_STAT(tp->t_dev);
678 /* assert(scp != NULL) */
679 /* scp is sc_console, if SC_VTY(dev) == SC_CONSOLECTL. */
683 error = (*scp->tsw->te_ioctl)(scp, tp, cmd, data, flag, td);
684 if (error != ENOIOCTL)
688 switch (cmd) { /* process console hardware related ioctl's */
690 case GIO_ATTR: /* get current attributes */
691 /* this ioctl is not processed here, but in the terminal emulator */
694 case GIO_COLOR: /* is this a color console ? */
695 *(int *)data = (sc->adp->va_flags & V_ADP_COLOR) ? 1 : 0;
698 case CONS_BLANKTIME: /* set screen saver timeout (0 = no saver) */
699 if (*(int *)data < 0 || *(int *)data > MAX_BLANKTIME)
702 scrn_blank_time = *(int *)data;
703 run_scrn_saver = (scrn_blank_time != 0);
707 case CONS_CURSORTYPE: /* set cursor type blink/noblink */
709 if (!ISGRAPHSC(sc->cur_scp))
710 sc_remove_cursor_image(sc->cur_scp);
711 if ((*(int*)data) & 0x01)
712 sc->flags |= SC_BLINK_CURSOR;
714 sc->flags &= ~SC_BLINK_CURSOR;
715 if ((*(int*)data) & 0x02) {
716 sc->flags |= SC_CHAR_CURSOR;
718 sc->flags &= ~SC_CHAR_CURSOR;
720 * The cursor shape is global property; all virtual consoles
721 * are affected. Update the cursor in the current console...
723 if (!ISGRAPHSC(sc->cur_scp)) {
724 sc_set_cursor_image(sc->cur_scp);
725 sc_draw_cursor_image(sc->cur_scp);
730 case CONS_BELLTYPE: /* set bell type sound/visual */
731 if ((*(int *)data) & 0x01)
732 sc->flags |= SC_VISUAL_BELL;
734 sc->flags &= ~SC_VISUAL_BELL;
735 if ((*(int *)data) & 0x02)
736 sc->flags |= SC_QUIET_BELL;
738 sc->flags &= ~SC_QUIET_BELL;
741 case CONS_GETINFO: /* get current (virtual) console info */
743 vid_info_t *ptr = (vid_info_t*)data;
744 if (ptr->size == sizeof(struct vid_info)) {
745 ptr->m_num = sc->cur_scp->index;
746 ptr->font_size = scp->font_size;
747 ptr->mv_col = scp->xpos;
748 ptr->mv_row = scp->ypos;
749 ptr->mv_csz = scp->xsize;
750 ptr->mv_rsz = scp->ysize;
752 * The following fields are filled by the terminal emulator. XXX
759 ptr->mv_grfc.fore = 0; /* not supported */
760 ptr->mv_grfc.back = 0; /* not supported */
761 ptr->mv_ovscan = scp->border;
762 if (scp == sc->cur_scp)
764 ptr->mk_keylock = scp->status & LOCK_MASK;
770 case CONS_GETVERS: /* get version number */
771 *(int*)data = 0x200; /* version 2.0 */
774 case CONS_IDLE: /* see if the screen has been idle */
776 * When the screen is in the GRAPHICS_MODE or UNKNOWN_MODE,
777 * the user process may have been writing something on the
778 * screen and syscons is not aware of it. Declare the screen
779 * is NOT idle if it is in one of these modes. But there is
780 * an exception to it; if a screen saver is running in the
781 * graphics mode in the current screen, we should say that the
782 * screen has been idle.
784 *(int *)data = (sc->flags & SC_SCRN_IDLE)
785 && (!ISGRAPHSC(sc->cur_scp)
786 || (sc->cur_scp->status & SAVER_RUNNING));
789 case CONS_SAVERMODE: /* set saver mode */
790 switch(*(int *)data) {
793 /* if a LKM screen saver is running, stop it first. */
794 scsplash_stick(FALSE);
795 saver_mode = *(int *)data;
798 if ((error = wait_scrn_saver_stop(NULL))) {
803 run_scrn_saver = TRUE;
804 if (saver_mode == CONS_USR_SAVER)
805 scp->status |= SAVER_RUNNING;
807 scp->status &= ~SAVER_RUNNING;
808 scsplash_stick(TRUE);
813 if ((saver_mode == CONS_USR_SAVER) && (scp->status & SAVER_RUNNING))
814 scp->status &= ~SAVER_RUNNING;
815 saver_mode = *(int *)data;
823 case CONS_SAVERSTART: /* immediately start/stop the screen saver */
825 * Note that this ioctl does not guarantee the screen saver
826 * actually starts or stops. It merely attempts to do so...
829 run_scrn_saver = (*(int *)data != 0);
831 sc->scrn_time_stamp -= scrn_blank_time;
835 case CONS_SCRSHOT: /* get a screen shot */
837 scrshot_t *ptr = (scrshot_t*)data;
839 if (ISGRAPHSC(scp)) {
843 if (scp->xsize != ptr->xsize || scp->ysize != ptr->ysize) {
847 copyout ((void*)scp->vtb.vtb_buffer, ptr->buf,
848 ptr->xsize * ptr->ysize * sizeof(uint16_t));
853 case VT_SETMODE: /* set screen switcher mode */
855 struct vt_mode *mode;
857 mode = (struct vt_mode *)data;
858 DPRINTF(5, ("sc%d: VT_SETMODE ", sc->unit));
859 if (scp->smode.mode == VT_PROCESS) {
860 if (scp->proc == pfind(scp->pid) && scp->proc != p) {
861 DPRINTF(5, ("error EPERM\n"));
866 if (mode->mode == VT_AUTO) {
867 scp->smode.mode = VT_AUTO;
870 DPRINTF(5, ("VT_AUTO, "));
871 if ((scp == sc->cur_scp) && (sc->unit == sc_console_unit))
872 cons_unavail = FALSE;
874 * note: must be called from a critical section because
875 * finish_vt_rel will call do_switch_scr which releases it
878 if (finish_vt_rel(scp, TRUE) == 0)
879 DPRINTF(5, ("reset WAIT_REL, "));
880 if (finish_vt_acq(scp) == 0)
881 DPRINTF(5, ("reset WAIT_ACQ, "));
883 if (!ISSIGVALID(mode->relsig) || !ISSIGVALID(mode->acqsig)
884 || !ISSIGVALID(mode->frsig)) {
886 DPRINTF(5, ("error EINVAL\n"));
889 DPRINTF(5, ("VT_PROCESS %d, ", p->p_pid));
890 bcopy(data, &scp->smode, sizeof(struct vt_mode));
892 scp->pid = scp->proc->p_pid;
893 if ((scp == sc->cur_scp) && (sc->unit == sc_console_unit))
901 case VT_GETMODE: /* get screen switcher mode */
902 bcopy(&scp->smode, data, sizeof(struct vt_mode));
905 case VT_RELDISP: /* screen switcher ioctl */
908 * This must be the current vty which is in the VT_PROCESS
911 if ((scp != sc->cur_scp) || (scp->smode.mode != VT_PROCESS)) {
915 /* ...and this process is controlling it. */
916 if (scp->proc != p) {
921 switch(*(int *)data) {
922 case VT_FALSE: /* user refuses to release screen, abort */
924 * note: must be called from a critical section because
925 * finish_vt_rel will call do_switch_scr which releases it
928 if ((error = finish_vt_rel(scp, FALSE)) == 0)
929 DPRINTF(5, ("sc%d: VT_FALSE\n", sc->unit));
931 case VT_TRUE: /* user has released screen, go on */
933 * note: must be called from a critical section because
934 * finish_vt_rel will call do_switch_scr which releases it
937 if ((error = finish_vt_rel(scp, TRUE)) == 0)
938 DPRINTF(5, ("sc%d: VT_TRUE\n", sc->unit));
940 case VT_ACKACQ: /* acquire acknowledged, switch completed */
941 if ((error = finish_vt_acq(scp)) == 0)
942 DPRINTF(5, ("sc%d: VT_ACKACQ\n", sc->unit));
950 case VT_OPENQRY: /* return free virtual console */
951 for (i = sc->first_vty; i < sc->first_vty + sc->vtys; i++) {
952 tp = VIRTUAL_TTY(sc, i);
953 if (!ISTTYOPEN(tp)) {
954 *(int *)data = i + 1;
960 case VT_ACTIVATE: /* switch to screen *data */
961 i = (*(int *)data == 0) ? scp->index : (*(int *)data - 1);
963 sc_clean_up(sc->cur_scp);
965 return sc_switch_scr(sc, i);
967 case VT_WAITACTIVE: /* wait for switch to occur */
968 i = (*(int *)data == 0) ? scp->index : (*(int *)data - 1);
969 if ((i < sc->first_vty) || (i >= sc->first_vty + sc->vtys))
972 error = sc_clean_up(sc->cur_scp);
976 scp = SC_STAT(SC_DEV(sc, i));
977 if (scp == scp->sc->cur_scp)
979 while ((error=tsleep((caddr_t)&scp->smode, PCATCH,
980 "waitvt", 0)) == ERESTART) ;
983 case VT_GETACTIVE: /* get active vty # */
984 *(int *)data = sc->cur_scp->index + 1;
987 case VT_GETINDEX: /* get this vty # */
988 *(int *)data = scp->index + 1;
991 case VT_LOCKSWITCH: /* prevent vty switching */
992 if ((*(int *)data) & 0x01)
993 sc->flags |= SC_SCRN_VTYLOCK;
995 sc->flags &= ~SC_SCRN_VTYLOCK;
998 case KDENABIO: /* allow io operations */
1002 if (securelevel > 0)
1004 p->p_md.md_regs->tf_eflags |= PSL_IOPL;
1007 case KDDISABIO: /* disallow io operations (default) */
1008 p->p_md.md_regs->tf_eflags &= ~PSL_IOPL;
1011 case KDSKBSTATE: /* set keyboard state (locks) */
1012 if (*(int *)data & ~LOCK_MASK)
1014 scp->status &= ~LOCK_MASK;
1015 scp->status |= *(int *)data;
1016 if (scp == sc->cur_scp)
1017 update_kbd_state(scp, scp->status, LOCK_MASK);
1020 case KDGKBSTATE: /* get keyboard state (locks) */
1021 if (scp == sc->cur_scp)
1022 save_kbd_state(scp);
1023 *(int *)data = scp->status & LOCK_MASK;
1026 case KDGETREPEAT: /* get keyboard repeat & delay rates */
1027 case KDSETREPEAT: /* set keyboard repeat & delay rates (new) */
1028 error = kbd_ioctl(sc->kbd, cmd, data);
1029 if (error == ENOIOCTL)
1033 case KDSETRAD: /* set keyboard repeat & delay rates (old) */
1034 if (*(int *)data & ~0x7f)
1036 error = kbd_ioctl(sc->kbd, cmd, data);
1037 if (error == ENOIOCTL)
1041 case KDSKBMODE: /* set keyboard mode */
1042 switch (*(int *)data) {
1043 case K_XLATE: /* switch to XLT ascii mode */
1044 case K_RAW: /* switch to RAW scancode mode */
1045 case K_CODE: /* switch to CODE mode */
1046 scp->kbd_mode = *(int *)data;
1047 if (scp == sc->cur_scp)
1048 kbd_ioctl(sc->kbd, cmd, data);
1055 case KDGKBMODE: /* get keyboard mode */
1056 *(int *)data = scp->kbd_mode;
1060 error = kbd_ioctl(sc->kbd, cmd, data);
1061 if (error == ENOIOCTL)
1065 case KDMKTONE: /* sound the bell */
1067 sc_bell(scp, (*(int*)data)&0xffff,
1068 (((*(int*)data)>>16)&0xffff)*hz/1000);
1070 sc_bell(scp, scp->bell_pitch, scp->bell_duration);
1073 case KIOCSOUND: /* make tone (*data) hz */
1074 if (scp == sc->cur_scp) {
1076 return sc_tone(*(int *)data);
1082 case KDGKBTYPE: /* get keyboard type */
1083 error = kbd_ioctl(sc->kbd, cmd, data);
1084 if (error == ENOIOCTL) {
1085 /* always return something? XXX */
1090 case KDSETLED: /* set keyboard LED status */
1091 if (*(int *)data & ~LED_MASK) /* FIXME: LOCK_MASK? */
1093 scp->status &= ~LED_MASK;
1094 scp->status |= *(int *)data;
1095 if (scp == sc->cur_scp)
1096 update_kbd_leds(scp, scp->status);
1099 case KDGETLED: /* get keyboard LED status */
1100 if (scp == sc->cur_scp)
1101 save_kbd_state(scp);
1102 *(int *)data = scp->status & LED_MASK;
1105 case CONS_SETKBD: /* set the new keyboard */
1110 newkbd = kbd_get_keyboard(*(int *)data);
1111 if (newkbd == NULL) {
1116 if (sc->kbd != newkbd) {
1117 i = kbd_allocate(newkbd->kb_name, newkbd->kb_unit,
1118 (void *)&sc->keyboard, sckbdevent, sc);
1119 /* i == newkbd->kb_index */
1121 if (sc->kbd != NULL) {
1122 save_kbd_state(sc->cur_scp);
1123 kbd_release(sc->kbd, (void *)&sc->keyboard);
1125 sc->kbd = kbd_get_keyboard(i); /* sc->kbd == newkbd */
1127 kbd_ioctl(sc->kbd, KDSKBMODE,
1128 (caddr_t)&sc->cur_scp->kbd_mode);
1129 update_kbd_state(sc->cur_scp, sc->cur_scp->status,
1132 error = EPERM; /* XXX */
1139 case CONS_RELKBD: /* release the current keyboard */
1142 if (sc->kbd != NULL) {
1143 save_kbd_state(sc->cur_scp);
1144 error = kbd_release(sc->kbd, (void *)&sc->keyboard);
1153 case CONS_GETTERM: /* get the current terminal emulator info */
1157 if (((term_info_t *)data)->ti_index == 0) {
1160 sw = sc_term_match_by_number(((term_info_t *)data)->ti_index);
1163 strncpy(((term_info_t *)data)->ti_name, sw->te_name,
1164 sizeof(((term_info_t *)data)->ti_name));
1165 strncpy(((term_info_t *)data)->ti_desc, sw->te_desc,
1166 sizeof(((term_info_t *)data)->ti_desc));
1167 ((term_info_t *)data)->ti_flags = 0;
1170 ((term_info_t *)data)->ti_name[0] = '\0';
1171 ((term_info_t *)data)->ti_desc[0] = '\0';
1172 ((term_info_t *)data)->ti_flags = 0;
1177 case CONS_SETTERM: /* set the current terminal emulator */
1179 error = sc_init_emulator(scp, ((term_info_t *)data)->ti_name);
1180 /* FIXME: what if scp == sc_console! XXX */
1184 case GIO_SCRNMAP: /* get output translation table */
1185 bcopy(&sc->scr_map, data, sizeof(sc->scr_map));
1188 case PIO_SCRNMAP: /* set output translation table */
1189 bcopy(data, &sc->scr_map, sizeof(sc->scr_map));
1190 for (i=0; i<sizeof(sc->scr_map); i++) {
1191 sc->scr_rmap[sc->scr_map[i]] = i;
1195 case GIO_KEYMAP: /* get keyboard translation table */
1196 case PIO_KEYMAP: /* set keyboard translation table */
1197 case GIO_DEADKEYMAP: /* get accent key translation table */
1198 case PIO_DEADKEYMAP: /* set accent key translation table */
1199 case GETFKEY: /* get function key string */
1200 case SETFKEY: /* set function key string */
1201 error = kbd_ioctl(sc->kbd, cmd, data);
1202 if (error == ENOIOCTL)
1206 #ifndef SC_NO_FONT_LOADING
1208 case PIO_FONT8x8: /* set 8x8 dot font */
1209 if (!ISFONTAVAIL(sc->adp->va_flags))
1211 bcopy(data, sc->font_8, 8*256);
1212 sc->fonts_loaded |= FONT_8;
1215 * Always use the font page #0. XXX
1216 * Don't load if the current font size is not 8x8.
1218 if (ISTEXTSC(sc->cur_scp) && (sc->cur_scp->font_size < 14))
1219 sc_load_font(sc->cur_scp, 0, 8, sc->font_8, 0, 256);
1222 case GIO_FONT8x8: /* get 8x8 dot font */
1223 if (!ISFONTAVAIL(sc->adp->va_flags))
1225 if (sc->fonts_loaded & FONT_8) {
1226 bcopy(sc->font_8, data, 8*256);
1232 case PIO_FONT8x14: /* set 8x14 dot font */
1233 if (!ISFONTAVAIL(sc->adp->va_flags))
1235 bcopy(data, sc->font_14, 14*256);
1236 sc->fonts_loaded |= FONT_14;
1239 * Always use the font page #0. XXX
1240 * Don't load if the current font size is not 8x14.
1242 if (ISTEXTSC(sc->cur_scp)
1243 && (sc->cur_scp->font_size >= 14)
1244 && (sc->cur_scp->font_size < 16))
1245 sc_load_font(sc->cur_scp, 0, 14, sc->font_14, 0, 256);
1248 case GIO_FONT8x14: /* get 8x14 dot font */
1249 if (!ISFONTAVAIL(sc->adp->va_flags))
1251 if (sc->fonts_loaded & FONT_14) {
1252 bcopy(sc->font_14, data, 14*256);
1258 case PIO_FONT8x16: /* set 8x16 dot font */
1259 if (!ISFONTAVAIL(sc->adp->va_flags))
1261 bcopy(data, sc->font_16, 16*256);
1262 sc->fonts_loaded |= FONT_16;
1265 * Always use the font page #0. XXX
1266 * Don't load if the current font size is not 8x16.
1268 if (ISTEXTSC(sc->cur_scp) && (sc->cur_scp->font_size >= 16))
1269 sc_load_font(sc->cur_scp, 0, 16, sc->font_16, 0, 256);
1272 case GIO_FONT8x16: /* get 8x16 dot font */
1273 if (!ISFONTAVAIL(sc->adp->va_flags))
1275 if (sc->fonts_loaded & FONT_16) {
1276 bcopy(sc->font_16, data, 16*256);
1282 #endif /* SC_NO_FONT_LOADING */
1288 error = (*linesw[tp->t_line].l_ioctl)(tp, cmd, data, flag, td);
1289 if (error != ENOIOCTL)
1291 error = ttioctl(tp, cmd, data, flag);
1292 if (error != ENOIOCTL)
1298 scstart(struct tty *tp)
1302 u_char buf[PCBURST];
1303 scr_stat *scp = SC_STAT(tp->t_dev);
1305 if (scp->status & SLKED ||
1306 (scp == scp->sc->cur_scp && scp->sc->blink_in_progress))
1309 if (!(tp->t_state & (TS_TIMEOUT | TS_BUSY | TS_TTSTOP))) {
1310 tp->t_state |= TS_BUSY;
1313 len = q_to_b(rbp, buf, PCBURST);
1315 sc_puts(scp, buf, len);
1318 tp->t_state &= ~TS_BUSY;
1325 sccnprobe(struct consdev *cp)
1330 cp->cn_pri = sc_get_cons_priority(&unit, &flags);
1332 /* a video card is always required */
1333 if (!scvidprobe(unit, flags, TRUE))
1334 cp->cn_pri = CN_DEAD;
1336 /* syscons will become console even when there is no keyboard */
1337 sckbdprobe(unit, flags, TRUE);
1339 if (cp->cn_pri == CN_DEAD)
1342 /* initialize required fields */
1343 cp->cn_dev = make_dev(&sc_cdevsw, SC_CONSOLECTL,
1344 UID_ROOT, GID_WHEEL, 0600, "consolectl");
1348 sccninit(struct consdev *cp)
1353 sc_get_cons_priority(&unit, &flags);
1354 scinit(unit, flags | SC_KERNEL_CONSOLE);
1355 sc_console_unit = unit;
1356 sc_console = SC_STAT(sc_get_softc(unit, SC_KERNEL_CONSOLE)->dev[0]);
1360 sccnterm(struct consdev *cp)
1362 /* we are not the kernel console any more, release everything */
1364 if (sc_console_unit < 0)
1365 return; /* shouldn't happen */
1368 sc_clear_screen(sc_console);
1369 sccnupdate(sc_console);
1371 scterm(sc_console_unit, SC_KERNEL_CONSOLE);
1372 sc_console_unit = -1;
1377 sccnputc(dev_t dev, int c)
1380 scr_stat *scp = sc_console;
1382 #ifndef SC_NO_HISTORY
1384 #endif /* !SC_NO_HISTORY */
1386 /* assert(sc_console != NULL) */
1388 #ifndef SC_NO_HISTORY
1389 if (scp == scp->sc->cur_scp && scp->status & SLKED) {
1390 scp->status &= ~SLKED;
1391 update_kbd_state(scp, scp->status, SLKED);
1392 if (scp->status & BUFFER_SAVED) {
1393 if (!sc_hist_restore(scp))
1394 sc_remove_cutmarking(scp);
1395 scp->status &= ~BUFFER_SAVED;
1396 scp->status |= CURSOR_ENABLED;
1397 sc_draw_cursor_image(scp);
1399 tp = VIRTUAL_TTY(scp->sc, scp->index);
1403 #endif /* !SC_NO_HISTORY */
1406 if (kernel_console_ts != NULL)
1407 scp->ts = kernel_console_ts;
1409 sc_puts(scp, buf, 1);
1420 return sccngetch(0);
1424 sccncheckc(dev_t dev)
1426 return sccngetch(SCGETC_NONBLOCK);
1430 sccndbctl(dev_t dev, int on)
1432 /* assert(sc_console_unit >= 0) */
1433 /* try to switch to the kernel console screen */
1434 if (on && debugger == 0) {
1436 * TRY to make sure the screen saver is stopped,
1437 * and the screen is updated before switching to
1442 && sc_console->sc->cur_scp->smode.mode == VT_AUTO
1443 && sc_console->smode.mode == VT_AUTO) {
1444 sc_console->sc->cur_scp->status |= MOUSE_HIDDEN;
1445 sc_switch_scr(sc_console->sc, sc_console->index);
1455 sccngetch(int flags)
1457 static struct fkeytab fkey;
1465 /* assert(sc_console != NULL) */
1468 * Stop the screen saver and update the screen if necessary.
1469 * What if we have been running in the screen saver code... XXX
1471 sc_touch_scrn_saver();
1472 scp = sc_console->sc->cur_scp; /* XXX */
1475 if (fkeycp < fkey.len) {
1477 return fkey.str[fkeycp++];
1480 if (scp->sc->kbd == NULL) {
1486 * Make sure the keyboard is accessible even when the kbd device
1487 * driver is disabled.
1489 kbd_enable(scp->sc->kbd);
1491 /* we shall always use the keyboard in the XLATE mode here */
1492 cur_mode = scp->kbd_mode;
1493 scp->kbd_mode = K_XLATE;
1494 kbd_ioctl(scp->sc->kbd, KDSKBMODE, (caddr_t)&scp->kbd_mode);
1496 kbd_poll(scp->sc->kbd, TRUE);
1497 c = scgetc(scp->sc, SCGETC_CN | flags);
1498 kbd_poll(scp->sc->kbd, FALSE);
1500 scp->kbd_mode = cur_mode;
1501 kbd_ioctl(scp->sc->kbd, KDSKBMODE, (caddr_t)&scp->kbd_mode);
1502 kbd_disable(scp->sc->kbd);
1505 switch (KEYFLAGS(c)) {
1506 case 0: /* normal char */
1508 case FKEY: /* function key */
1509 p = kbd_get_fkeystr(scp->sc->kbd, KEYCHAR(c), (size_t *)&fkeycp);
1511 if ((p != NULL) && (fkey.len > 0)) {
1512 bcopy(p, fkey.str, fkey.len);
1526 sccnupdate(scr_stat *scp)
1528 /* this is a cut-down version of scrn_timer()... */
1530 if (scp->sc->font_loading_in_progress || scp->sc->videoio_in_progress)
1533 if (debugger > 0 || panicstr || shutdown_in_progress) {
1534 sc_touch_scrn_saver();
1535 } else if (scp != scp->sc->cur_scp) {
1539 if (!run_scrn_saver)
1540 scp->sc->flags &= ~SC_SCRN_IDLE;
1542 if ((saver_mode != CONS_LKM_SAVER) || !(scp->sc->flags & SC_SCRN_IDLE))
1543 if (scp->sc->flags & SC_SCRN_BLANKED)
1544 stop_scrn_saver(scp->sc, current_saver);
1545 #endif /* NSPLASH */
1547 if (scp != scp->sc->cur_scp || scp->sc->blink_in_progress
1548 || scp->sc->switch_in_progress)
1551 * FIXME: unlike scrn_timer(), we call scrn_update() from here even
1552 * when write_in_progress is non-zero. XXX
1555 if (!ISGRAPHSC(scp) && !(scp->sc->flags & SC_SCRN_BLANKED))
1556 scrn_update(scp, TRUE);
1560 scrn_timer(void *arg)
1562 static int kbd_interval = 0;
1568 again = (arg != NULL);
1570 sc = (sc_softc_t *)arg;
1571 else if (sc_console != NULL)
1572 sc = sc_console->sc;
1576 /* don't do anything when we are performing some I/O operations */
1577 if (sc->font_loading_in_progress || sc->videoio_in_progress) {
1579 callout_reset(&sc->scrn_timer_ch, hz / 10, scrn_timer, sc);
1584 if ((sc->kbd == NULL) && (sc->config & SC_AUTODETECT_KBD)) {
1585 /* try to allocate a keyboard automatically */
1586 if (++kbd_interval >= 25) {
1587 sc->keyboard = kbd_allocate("*", -1, (void *)&sc->keyboard,
1589 if (sc->keyboard >= 0) {
1590 sc->kbd = kbd_get_keyboard(sc->keyboard);
1591 kbd_ioctl(sc->kbd, KDSKBMODE,
1592 (caddr_t)&sc->cur_scp->kbd_mode);
1593 update_kbd_state(sc->cur_scp, sc->cur_scp->status,
1600 /* find the vty to update */
1603 /* should we stop the screen saver? */
1604 getmicrouptime(&tv);
1605 if (debugger > 0 || panicstr || shutdown_in_progress)
1606 sc_touch_scrn_saver();
1607 if (run_scrn_saver) {
1608 if (tv.tv_sec > sc->scrn_time_stamp + scrn_blank_time)
1609 sc->flags |= SC_SCRN_IDLE;
1611 sc->flags &= ~SC_SCRN_IDLE;
1613 sc->scrn_time_stamp = tv.tv_sec;
1614 sc->flags &= ~SC_SCRN_IDLE;
1615 if (scrn_blank_time > 0)
1616 run_scrn_saver = TRUE;
1619 if ((saver_mode != CONS_LKM_SAVER) || !(sc->flags & SC_SCRN_IDLE))
1620 if (sc->flags & SC_SCRN_BLANKED)
1621 stop_scrn_saver(sc, current_saver);
1622 #endif /* NSPLASH */
1624 /* should we just return ? */
1625 if (sc->blink_in_progress || sc->switch_in_progress
1626 || sc->write_in_progress) {
1628 callout_reset(&sc->scrn_timer_ch, hz / 10, scrn_timer, sc);
1633 /* Update the screen */
1634 scp = sc->cur_scp; /* cur_scp may have changed... */
1635 if (!ISGRAPHSC(scp) && !(sc->flags & SC_SCRN_BLANKED))
1636 scrn_update(scp, TRUE);
1639 /* should we activate the screen saver? */
1640 if ((saver_mode == CONS_LKM_SAVER) && (sc->flags & SC_SCRN_IDLE))
1641 if (!ISGRAPHSC(scp) || (sc->flags & SC_SCRN_BLANKED))
1642 (*current_saver)(sc, TRUE);
1643 #endif /* NSPLASH */
1646 callout_reset(&sc->scrn_timer_ch, hz / 25, scrn_timer, sc);
1651 and_region(int *s1, int *e1, int s2, int e2)
1653 if (*e1 < s2 || e2 < *s1)
1655 *s1 = imax(*s1, s2);
1656 *e1 = imin(*e1, e2);
1661 scrn_update(scr_stat *scp, int show_cursor)
1668 /* assert(scp == scp->sc->cur_scp) */
1670 ++scp->sc->videoio_in_progress;
1672 #ifndef SC_NO_CUTPASTE
1673 /* remove the previous mouse pointer image if necessary */
1674 if (scp->status & MOUSE_VISIBLE) {
1676 e = scp->mouse_pos + scp->xsize + 1;
1677 if ((scp->status & (MOUSE_MOVED | MOUSE_HIDDEN))
1678 || and_region(&s, &e, scp->start, scp->end)
1679 || ((scp->status & CURSOR_ENABLED) &&
1680 (scp->cursor_pos != scp->cursor_oldpos) &&
1681 (and_region(&s, &e, scp->cursor_pos, scp->cursor_pos)
1682 || and_region(&s, &e, scp->cursor_oldpos, scp->cursor_oldpos)))) {
1683 sc_remove_mouse_image(scp);
1684 if (scp->end >= scp->xsize*scp->ysize)
1685 scp->end = scp->xsize*scp->ysize - 1;
1688 #endif /* !SC_NO_CUTPASTE */
1692 if (scp->end >= scp->xsize*scp->ysize) {
1693 printf("scrn_update(): scp->end %d > size_of_screen!!\n", scp->end);
1694 scp->end = scp->xsize*scp->ysize - 1;
1696 if (scp->start < 0) {
1697 printf("scrn_update(): scp->start %d < 0\n", scp->start);
1702 /* update screen image */
1703 if (scp->start <= scp->end) {
1704 if (scp->mouse_cut_end >= 0) {
1705 /* there is a marked region for cut & paste */
1706 if (scp->mouse_cut_start <= scp->mouse_cut_end) {
1707 start = scp->mouse_cut_start;
1708 end = scp->mouse_cut_end;
1710 start = scp->mouse_cut_end;
1711 end = scp->mouse_cut_start - 1;
1715 /* does the cut-mark region overlap with the update region? */
1716 if (and_region(&s, &e, scp->start, scp->end)) {
1717 (*scp->rndr->draw)(scp, s, e - s + 1, TRUE);
1720 if (and_region(&s, &e, scp->start, scp->end))
1721 (*scp->rndr->draw)(scp, s, e - s + 1, FALSE);
1723 e = scp->xsize*scp->ysize - 1;
1724 if (and_region(&s, &e, scp->start, scp->end))
1725 (*scp->rndr->draw)(scp, s, e - s + 1, FALSE);
1727 (*scp->rndr->draw)(scp, scp->start,
1728 scp->end - scp->start + 1, FALSE);
1731 (*scp->rndr->draw)(scp, scp->start,
1732 scp->end - scp->start + 1, FALSE);
1736 /* we are not to show the cursor and the mouse pointer... */
1739 scp->start = scp->xsize*scp->ysize - 1;
1740 --scp->sc->videoio_in_progress;
1744 /* update cursor image */
1745 if (scp->status & CURSOR_ENABLED) {
1748 /* did cursor move since last time ? */
1749 if (scp->cursor_pos != scp->cursor_oldpos) {
1750 /* do we need to remove old cursor image ? */
1751 if (!and_region(&s, &e, scp->cursor_oldpos, scp->cursor_oldpos))
1752 sc_remove_cursor_image(scp);
1753 sc_draw_cursor_image(scp);
1755 if (and_region(&s, &e, scp->cursor_pos, scp->cursor_pos))
1756 /* cursor didn't move, but has been overwritten */
1757 sc_draw_cursor_image(scp);
1758 else if (scp->sc->flags & SC_BLINK_CURSOR)
1759 /* if it's a blinking cursor, update it */
1760 (*scp->rndr->blink_cursor)(scp, scp->cursor_pos,
1761 sc_inside_cutmark(scp,
1766 #ifndef SC_NO_CUTPASTE
1767 /* update "pseudo" mouse pointer image */
1768 if (scp->sc->flags & SC_MOUSE_ENABLED) {
1769 if (!(scp->status & (MOUSE_VISIBLE | MOUSE_HIDDEN))) {
1770 scp->status &= ~MOUSE_MOVED;
1771 sc_draw_mouse_image(scp);
1774 #endif /* SC_NO_CUTPASTE */
1777 scp->start = scp->xsize*scp->ysize - 1;
1779 --scp->sc->videoio_in_progress;
1784 scsplash_callback(int event, void *arg)
1789 sc = (sc_softc_t *)arg;
1793 if (add_scrn_saver(scsplash_saver) == 0) {
1794 sc->flags &= ~SC_SAVER_FAILED;
1795 run_scrn_saver = TRUE;
1796 if (cold && !(boothowto & (RB_VERBOSE | RB_CONFIG))) {
1797 scsplash_stick(TRUE);
1798 (*current_saver)(sc, TRUE);
1804 if (current_saver == scsplash_saver) {
1805 scsplash_stick(FALSE);
1806 error = remove_scrn_saver(scsplash_saver);
1818 scsplash_saver(sc_softc_t *sc, int show)
1820 static int busy = FALSE;
1829 if (!(sc->flags & SC_SAVER_FAILED)) {
1830 if (!(sc->flags & SC_SCRN_BLANKED))
1831 set_scrn_saver_mode(scp, -1, NULL, 0);
1832 switch (splash(sc->adp, TRUE)) {
1833 case 0: /* succeeded */
1835 case EAGAIN: /* try later */
1836 restore_scrn_saver_mode(scp, FALSE);
1837 sc_touch_scrn_saver(); /* XXX */
1840 sc->flags |= SC_SAVER_FAILED;
1841 scsplash_stick(FALSE);
1842 restore_scrn_saver_mode(scp, TRUE);
1843 printf("scsplash_saver(): failed to put up the image\n");
1847 } else if (!sticky_splash) {
1848 if ((sc->flags & SC_SCRN_BLANKED) && (splash(sc->adp, FALSE) == 0))
1849 restore_scrn_saver_mode(scp, TRUE);
1855 add_scrn_saver(void (*this_saver)(sc_softc_t *, int))
1860 if (current_saver != none_saver) {
1861 error = remove_scrn_saver(current_saver);
1866 if (current_saver != none_saver)
1869 run_scrn_saver = FALSE;
1870 saver_mode = CONS_LKM_SAVER;
1871 current_saver = this_saver;
1876 remove_scrn_saver(void (*this_saver)(sc_softc_t *, int))
1878 if (current_saver != this_saver)
1883 * In order to prevent `current_saver' from being called by
1884 * the timeout routine `scrn_timer()' while we manipulate
1885 * the saver list, we shall set `current_saver' to `none_saver'
1886 * before stopping the current saver, rather than blocking by `splXX()'.
1888 current_saver = none_saver;
1890 stop_scrn_saver(this_saver);
1893 /* unblank all blanked screens */
1894 wait_scrn_saver_stop(NULL);
1898 current_saver = none_saver;
1903 set_scrn_saver_mode(scr_stat *scp, int mode, u_char *pal, int border)
1906 /* assert(scp == scp->sc->cur_scp) */
1908 if (!ISGRAPHSC(scp))
1909 sc_remove_cursor_image(scp);
1910 scp->splash_save_mode = scp->mode;
1911 scp->splash_save_status = scp->status & (GRAPHICS_MODE | PIXEL_MODE);
1912 scp->status &= ~(GRAPHICS_MODE | PIXEL_MODE);
1913 scp->status |= (UNKNOWN_MODE | SAVER_RUNNING);
1914 scp->sc->flags |= SC_SCRN_BLANKED;
1920 if (set_mode(scp) == 0) {
1921 if (scp->sc->adp->va_info.vi_flags & V_INFO_GRAPHICS)
1922 scp->status |= GRAPHICS_MODE;
1923 #ifndef SC_NO_PALETTE_LOADING
1925 load_palette(scp->sc->adp, pal);
1927 sc_set_border(scp, border);
1931 scp->mode = scp->splash_save_mode;
1932 scp->status &= ~(UNKNOWN_MODE | SAVER_RUNNING);
1933 scp->status |= scp->splash_save_status;
1940 restore_scrn_saver_mode(scr_stat *scp, int changemode)
1945 /* assert(scp == scp->sc->cur_scp) */
1948 status = scp->status;
1949 scp->mode = scp->splash_save_mode;
1950 scp->status &= ~(UNKNOWN_MODE | SAVER_RUNNING);
1951 scp->status |= scp->splash_save_status;
1952 scp->sc->flags &= ~SC_SCRN_BLANKED;
1954 if (!ISGRAPHSC(scp))
1955 sc_draw_cursor_image(scp);
1960 if (set_mode(scp) == 0) {
1961 #ifndef SC_NO_PALETTE_LOADING
1962 load_palette(scp->sc->adp, scp->sc->palette);
1969 scp->status = status;
1976 stop_scrn_saver(sc_softc_t *sc, void (*saver)(sc_softc_t *, int))
1978 (*saver)(sc, FALSE);
1979 run_scrn_saver = FALSE;
1980 /* the screen saver may have chosen not to stop after all... */
1981 if (sc->flags & SC_SCRN_BLANKED)
1984 mark_all(sc->cur_scp);
1985 if (sc->delayed_next_scr)
1986 sc_switch_scr(sc, sc->delayed_next_scr - 1);
1987 wakeup((caddr_t)&scrn_blanked);
1991 wait_scrn_saver_stop(sc_softc_t *sc)
1995 while (scrn_blanked > 0) {
1996 run_scrn_saver = FALSE;
1997 if (sc && !(sc->flags & SC_SCRN_BLANKED)) {
2001 error = tsleep((caddr_t)&scrn_blanked, PCATCH, "scrsav", 0);
2002 if ((error != 0) && (error != ERESTART))
2005 run_scrn_saver = FALSE;
2008 #endif /* NSPLASH */
2011 sc_touch_scrn_saver(void)
2013 scsplash_stick(FALSE);
2014 run_scrn_saver = FALSE;
2018 sc_switch_scr(sc_softc_t *sc, u_int next_scr)
2023 DPRINTF(5, ("sc0: sc_switch_scr() %d ", next_scr + 1));
2025 /* prevent switch if previously requested */
2026 if (sc->flags & SC_SCRN_VTYLOCK) {
2027 sc_bell(sc->cur_scp, sc->cur_scp->bell_pitch,
2028 sc->cur_scp->bell_duration);
2032 /* delay switch if the screen is blanked or being updated */
2033 if ((sc->flags & SC_SCRN_BLANKED) || sc->write_in_progress
2034 || sc->blink_in_progress || sc->videoio_in_progress) {
2035 sc->delayed_next_scr = next_scr + 1;
2036 sc_touch_scrn_saver();
2037 DPRINTF(5, ("switch delayed\n"));
2042 cur_scp = sc->cur_scp;
2044 /* we are in the middle of the vty switching process... */
2045 if (sc->switch_in_progress
2046 && (cur_scp->smode.mode == VT_PROCESS)
2048 if (cur_scp->proc != pfind(cur_scp->pid)) {
2050 * The controlling process has died!!. Do some clean up.
2051 * NOTE:`cur_scp->proc' and `cur_scp->smode.mode'
2052 * are not reset here yet; they will be cleared later.
2054 DPRINTF(5, ("cur_scp controlling process %d died, ",
2056 if (cur_scp->status & SWITCH_WAIT_REL) {
2058 * Force the previous switch to finish, but return now
2061 * note: must be called from a critical section because
2062 * finish_vt_rel will call do_switch_scr which releases it
2065 DPRINTF(5, ("reset WAIT_REL, "));
2066 finish_vt_rel(cur_scp, TRUE);
2068 DPRINTF(5, ("finishing previous switch\n"));
2070 } else if (cur_scp->status & SWITCH_WAIT_ACQ) {
2071 /* let's assume screen switch has been completed. */
2072 DPRINTF(5, ("reset WAIT_ACQ, "));
2073 finish_vt_acq(cur_scp);
2076 * We are in between screen release and acquisition, and
2077 * reached here via scgetc() or scrn_timer() which has
2078 * interrupted exchange_scr(). Don't do anything stupid.
2080 DPRINTF(5, ("waiting nothing, "));
2084 * The controlling process is alive, but not responding...
2085 * It is either buggy or it may be just taking time.
2086 * The following code is a gross kludge to cope with this
2087 * problem for which there is no clean solution. XXX
2089 if (cur_scp->status & SWITCH_WAIT_REL) {
2090 switch (sc->switch_in_progress++) {
2094 DPRINTF(5, ("sending relsig again, "));
2095 signal_vt_rel(cur_scp);
2102 * Act as if the controlling program returned
2105 * note: must be called from a critical section because
2106 * finish_vt_rel will call do_switch_scr which releases it
2109 DPRINTF(5, ("force reset WAIT_REL, "));
2110 finish_vt_rel(cur_scp, FALSE);
2112 DPRINTF(5, ("act as if VT_FALSE was seen\n"));
2115 } else if (cur_scp->status & SWITCH_WAIT_ACQ) {
2116 switch (sc->switch_in_progress++) {
2120 DPRINTF(5, ("sending acqsig again, "));
2121 signal_vt_acq(cur_scp);
2127 /* clear the flag and finish the previous switch */
2128 DPRINTF(5, ("force reset WAIT_ACQ, "));
2129 finish_vt_acq(cur_scp);
2137 * Return error if an invalid argument is given, or vty switch
2138 * is still in progress.
2140 if ((next_scr < sc->first_vty) || (next_scr >= sc->first_vty + sc->vtys)
2141 || sc->switch_in_progress) {
2143 sc_bell(cur_scp, bios_value.bell_pitch, BELL_DURATION);
2144 DPRINTF(5, ("error 1\n"));
2149 * Don't allow switching away from the graphics mode vty
2150 * if the switch mode is VT_AUTO, unless the next vty is the same
2151 * as the current or the current vty has been closed (but showing).
2153 tp = VIRTUAL_TTY(sc, cur_scp->index);
2154 if ((cur_scp->index != next_scr)
2156 && (cur_scp->smode.mode == VT_AUTO)
2157 && ISGRAPHSC(cur_scp)) {
2159 sc_bell(cur_scp, bios_value.bell_pitch, BELL_DURATION);
2160 DPRINTF(5, ("error, graphics mode\n"));
2165 * Is the wanted vty open? Don't allow switching to a closed vty.
2166 * If we are in DDB, don't switch to a vty in the VT_PROCESS mode.
2167 * Note that we always allow the user to switch to the kernel
2168 * console even if it is closed.
2170 if ((sc_console == NULL) || (next_scr != sc_console->index)) {
2171 tp = VIRTUAL_TTY(sc, next_scr);
2172 if (!ISTTYOPEN(tp)) {
2174 sc_bell(cur_scp, bios_value.bell_pitch, BELL_DURATION);
2175 DPRINTF(5, ("error 2, requested vty isn't open!\n"));
2178 if ((debugger > 0) && (SC_STAT(tp->t_dev)->smode.mode == VT_PROCESS)) {
2180 DPRINTF(5, ("error 3, requested vty is in the VT_PROCESS mode\n"));
2185 /* this is the start of vty switching process... */
2186 ++sc->switch_in_progress;
2187 sc->delayed_next_scr = 0;
2188 sc->old_scp = cur_scp;
2189 sc->new_scp = SC_STAT(SC_DEV(sc, next_scr));
2190 if (sc->new_scp == sc->old_scp) {
2191 sc->switch_in_progress = 0;
2192 wakeup((caddr_t)&sc->new_scp->smode);
2194 DPRINTF(5, ("switch done (new == old)\n"));
2198 /* has controlling process died? */
2199 vt_proc_alive(sc->old_scp);
2200 vt_proc_alive(sc->new_scp);
2202 /* wait for the controlling process to release the screen, if necessary */
2203 if (signal_vt_rel(sc->old_scp)) {
2208 /* go set up the new vty screen */
2213 /* wake up processes waiting for this vty */
2214 wakeup((caddr_t)&sc->cur_scp->smode);
2216 /* wait for the controlling process to acknowledge, if necessary */
2217 if (signal_vt_acq(sc->cur_scp)) {
2222 sc->switch_in_progress = 0;
2223 if (sc->unit == sc_console_unit)
2224 cons_unavail = FALSE;
2226 DPRINTF(5, ("switch done\n"));
2232 * NOTE: must be called from a critical section because do_switch_scr
2233 * will release it temporarily.
2236 do_switch_scr(sc_softc_t *sc)
2238 vt_proc_alive(sc->new_scp);
2243 /* sc->cur_scp == sc->new_scp */
2244 wakeup((caddr_t)&sc->cur_scp->smode);
2246 /* wait for the controlling process to acknowledge, if necessary */
2247 if (!signal_vt_acq(sc->cur_scp)) {
2248 sc->switch_in_progress = 0;
2249 if (sc->unit == sc_console_unit)
2250 cons_unavail = FALSE;
2255 vt_proc_alive(scr_stat *scp)
2258 if (scp->proc == pfind(scp->pid))
2261 scp->smode.mode = VT_AUTO;
2262 DPRINTF(5, ("vt controlling process %d died\n", scp->pid));
2268 signal_vt_rel(scr_stat *scp)
2270 if (scp->smode.mode != VT_PROCESS)
2272 scp->status |= SWITCH_WAIT_REL;
2273 psignal(scp->proc, scp->smode.relsig);
2274 DPRINTF(5, ("sending relsig to %d\n", scp->pid));
2279 signal_vt_acq(scr_stat *scp)
2281 if (scp->smode.mode != VT_PROCESS)
2283 if (scp->sc->unit == sc_console_unit)
2284 cons_unavail = TRUE;
2285 scp->status |= SWITCH_WAIT_ACQ;
2286 psignal(scp->proc, scp->smode.acqsig);
2287 DPRINTF(5, ("sending acqsig to %d\n", scp->pid));
2292 * NOTE: must be called from a critical section because do_switch_scr
2293 * will release it temporarily.
2296 finish_vt_rel(scr_stat *scp, int release)
2298 if (scp == scp->sc->old_scp && scp->status & SWITCH_WAIT_REL) {
2299 scp->status &= ~SWITCH_WAIT_REL;
2301 do_switch_scr(scp->sc);
2303 scp->sc->switch_in_progress = 0;
2310 finish_vt_acq(scr_stat *scp)
2312 if (scp == scp->sc->new_scp && scp->status & SWITCH_WAIT_ACQ) {
2313 scp->status &= ~SWITCH_WAIT_ACQ;
2314 scp->sc->switch_in_progress = 0;
2321 exchange_scr(sc_softc_t *sc)
2325 /* save the current state of video and keyboard */
2326 sc_move_cursor(sc->old_scp, sc->old_scp->xpos, sc->old_scp->ypos);
2327 if (!ISGRAPHSC(sc->old_scp))
2328 sc_remove_cursor_image(sc->old_scp);
2329 if (sc->old_scp->kbd_mode == K_XLATE)
2330 save_kbd_state(sc->old_scp);
2332 /* set up the video for the new screen */
2333 scp = sc->cur_scp = sc->new_scp;
2334 if (sc->old_scp->mode != scp->mode || ISUNKNOWNSC(sc->old_scp))
2337 sc_vtb_init(&scp->scr, VTB_FRAMEBUFFER, scp->xsize, scp->ysize,
2338 (void *)sc->adp->va_window, FALSE);
2339 scp->status |= MOUSE_HIDDEN;
2340 sc_move_cursor(scp, scp->xpos, scp->ypos);
2341 if (!ISGRAPHSC(scp))
2342 sc_set_cursor_image(scp);
2343 #ifndef SC_NO_PALETTE_LOADING
2344 if (ISGRAPHSC(sc->old_scp))
2345 load_palette(sc->adp, sc->palette);
2347 sc_set_border(scp, scp->border);
2349 /* set up the keyboard for the new screen */
2350 if (sc->old_scp->kbd_mode != scp->kbd_mode)
2351 kbd_ioctl(sc->kbd, KDSKBMODE, (caddr_t)&scp->kbd_mode);
2352 update_kbd_state(scp, scp->status, LOCK_MASK);
2358 sc_puts(scr_stat *scp, u_char *buf, int len)
2361 /* make screensaver happy */
2362 if (!sticky_splash && scp == scp->sc->cur_scp)
2363 run_scrn_saver = FALSE;
2367 (*scp->tsw->te_puts)(scp, buf, len);
2369 if (scp->sc->delayed_next_scr)
2370 sc_switch_scr(scp->sc, scp->sc->delayed_next_scr - 1);
2374 sc_draw_cursor_image(scr_stat *scp)
2376 /* assert(scp == scp->sc->cur_scp); */
2377 ++scp->sc->videoio_in_progress;
2378 (*scp->rndr->draw_cursor)(scp, scp->cursor_pos,
2379 scp->sc->flags & SC_BLINK_CURSOR, TRUE,
2380 sc_inside_cutmark(scp, scp->cursor_pos));
2381 scp->cursor_oldpos = scp->cursor_pos;
2382 --scp->sc->videoio_in_progress;
2386 sc_remove_cursor_image(scr_stat *scp)
2388 /* assert(scp == scp->sc->cur_scp); */
2389 ++scp->sc->videoio_in_progress;
2390 (*scp->rndr->draw_cursor)(scp, scp->cursor_oldpos,
2391 scp->sc->flags & SC_BLINK_CURSOR, FALSE,
2392 sc_inside_cutmark(scp, scp->cursor_oldpos));
2393 --scp->sc->videoio_in_progress;
2397 update_cursor_image(scr_stat *scp)
2401 if (scp->sc->flags & SC_CHAR_CURSOR) {
2402 scp->cursor_base = imax(0, scp->sc->cursor_base);
2403 scp->cursor_height = imin(scp->sc->cursor_height, scp->font_size);
2405 scp->cursor_base = 0;
2406 scp->cursor_height = scp->font_size;
2408 blink = scp->sc->flags & SC_BLINK_CURSOR;
2410 /* assert(scp == scp->sc->cur_scp); */
2411 ++scp->sc->videoio_in_progress;
2412 (*scp->rndr->draw_cursor)(scp, scp->cursor_oldpos, blink, FALSE,
2413 sc_inside_cutmark(scp, scp->cursor_pos));
2414 (*scp->rndr->set_cursor)(scp, scp->cursor_base, scp->cursor_height, blink);
2415 (*scp->rndr->draw_cursor)(scp, scp->cursor_pos, blink, TRUE,
2416 sc_inside_cutmark(scp, scp->cursor_pos));
2417 --scp->sc->videoio_in_progress;
2421 sc_set_cursor_image(scr_stat *scp)
2423 if (scp->sc->flags & SC_CHAR_CURSOR) {
2424 scp->cursor_base = imax(0, scp->sc->cursor_base);
2425 scp->cursor_height = imin(scp->sc->cursor_height, scp->font_size);
2427 scp->cursor_base = 0;
2428 scp->cursor_height = scp->font_size;
2431 /* assert(scp == scp->sc->cur_scp); */
2432 ++scp->sc->videoio_in_progress;
2433 (*scp->rndr->set_cursor)(scp, scp->cursor_base, scp->cursor_height,
2434 scp->sc->flags & SC_BLINK_CURSOR);
2435 --scp->sc->videoio_in_progress;
2439 scinit(int unit, int flags)
2442 * When syscons is being initialized as the kernel console, malloc()
2443 * is not yet functional, because various kernel structures has not been
2444 * fully initialized yet. Therefore, we need to declare the following
2445 * static buffers for the console. This is less than ideal,
2446 * but is necessry evil for the time being. XXX
2448 static scr_stat main_console;
2449 static dev_t main_devs[MAXCONS];
2450 static struct tty main_tty;
2451 static u_short sc_buffer[ROW*COL]; /* XXX */
2452 #ifndef SC_NO_FONT_LOADING
2453 static u_char font_8[256*8];
2454 static u_char font_14[256*14];
2455 static u_char font_16[256*16];
2460 video_adapter_t *adp;
2465 /* one time initialization */
2466 if (init_done == COLD)
2467 sc_get_bios_values(&bios_value);
2471 * Allocate resources. Even if we are being called for the second
2472 * time, we must allocate them again, because they might have
2475 sc = sc_get_softc(unit, flags & SC_KERNEL_CONSOLE);
2477 if (sc->adapter >= 0) {
2478 vid_release(sc->adp, (void *)&sc->adapter);
2482 if (sc->keyboard >= 0) {
2483 DPRINTF(5, ("sc%d: releasing kbd%d\n", unit, sc->keyboard));
2484 i = kbd_release(sc->kbd, (void *)&sc->keyboard);
2485 DPRINTF(5, ("sc%d: kbd_release returned %d\n", unit, i));
2486 if (sc->kbd != NULL) {
2487 DPRINTF(5, ("sc%d: kbd != NULL!, index:%d, unit:%d, flags:0x%x\n",
2488 unit, sc->kbd->kb_index, sc->kbd->kb_unit, sc->kbd->kb_flags));
2492 sc->adapter = vid_allocate("*", unit, (void *)&sc->adapter);
2493 sc->adp = vid_get_adapter(sc->adapter);
2494 /* assert((sc->adapter >= 0) && (sc->adp != NULL)) */
2495 sc->keyboard = kbd_allocate("*", unit, (void *)&sc->keyboard,
2497 DPRINTF(1, ("sc%d: keyboard %d\n", unit, sc->keyboard));
2498 sc->kbd = kbd_get_keyboard(sc->keyboard);
2499 if (sc->kbd != NULL) {
2500 DPRINTF(1, ("sc%d: kbd index:%d, unit:%d, flags:0x%x\n",
2501 unit, sc->kbd->kb_index, sc->kbd->kb_unit, sc->kbd->kb_flags));
2504 if (!(sc->flags & SC_INIT_DONE) || (adp != sc->adp)) {
2506 sc->initial_mode = sc->adp->va_initial_mode;
2508 #ifndef SC_NO_FONT_LOADING
2509 if (flags & SC_KERNEL_CONSOLE) {
2510 sc->font_8 = font_8;
2511 sc->font_14 = font_14;
2512 sc->font_16 = font_16;
2513 } else if (sc->font_8 == NULL) {
2514 /* assert(sc_malloc) */
2515 sc->font_8 = malloc(sizeof(font_8), M_SYSCONS, M_WAITOK);
2516 sc->font_14 = malloc(sizeof(font_14), M_SYSCONS, M_WAITOK);
2517 sc->font_16 = malloc(sizeof(font_16), M_SYSCONS, M_WAITOK);
2521 /* extract the hardware cursor location and hide the cursor for now */
2522 (*vidsw[sc->adapter]->read_hw_cursor)(sc->adp, &col, &row);
2523 (*vidsw[sc->adapter]->set_hw_cursor)(sc->adp, -1, -1);
2525 /* set up the first console */
2526 sc->first_vty = unit*MAXCONS;
2527 sc->vtys = MAXCONS; /* XXX: should be configurable */
2528 if (flags & SC_KERNEL_CONSOLE) {
2529 sc->dev = main_devs;
2530 sc->dev[0] = make_dev(&sc_cdevsw, unit*MAXCONS, UID_ROOT,
2531 GID_WHEEL, 0600, "ttyv%r", unit*MAXCONS);
2532 sc->dev[0]->si_tty = &main_tty;
2533 ttyregister(&main_tty);
2534 scp = &main_console;
2535 init_scp(sc, sc->first_vty, scp);
2536 sc_vtb_init(&scp->vtb, VTB_MEMORY, scp->xsize, scp->ysize,
2537 (void *)sc_buffer, FALSE);
2538 if (sc_init_emulator(scp, SC_DFLT_TERM))
2539 sc_init_emulator(scp, "*");
2540 (*scp->tsw->te_default_attr)(scp,
2541 kernel_default.std_color,
2542 kernel_default.rev_color);
2544 /* assert(sc_malloc) */
2545 sc->dev = malloc(sizeof(dev_t)*sc->vtys, M_SYSCONS, M_WAITOK | M_ZERO);
2546 sc->dev[0] = make_dev(&sc_cdevsw, unit*MAXCONS, UID_ROOT,
2547 GID_WHEEL, 0600, "ttyv%r", unit*MAXCONS);
2548 sc->dev[0]->si_tty = ttymalloc(sc->dev[0]->si_tty);
2549 scp = alloc_scp(sc, sc->first_vty);
2551 sc->dev[0]->si_drv1 = scp;
2554 /* copy screen to temporary buffer */
2555 sc_vtb_init(&scp->scr, VTB_FRAMEBUFFER, scp->xsize, scp->ysize,
2556 (void *)scp->sc->adp->va_window, FALSE);
2558 sc_vtb_copy(&scp->scr, 0, &scp->vtb, 0, scp->xsize*scp->ysize);
2560 /* move cursors to the initial positions */
2561 if (col >= scp->xsize)
2563 if (row >= scp->ysize)
2564 row = scp->ysize - 1;
2567 scp->cursor_pos = scp->cursor_oldpos = row*scp->xsize + col;
2568 if (bios_value.cursor_end < scp->font_size)
2569 sc->cursor_base = scp->font_size - bios_value.cursor_end - 1;
2571 sc->cursor_base = 0;
2572 i = bios_value.cursor_end - bios_value.cursor_start + 1;
2573 sc->cursor_height = imin(i, scp->font_size);
2574 #ifndef SC_NO_SYSMOUSE
2575 sc_mouse_move(scp, scp->xpixel/2, scp->ypixel/2);
2577 if (!ISGRAPHSC(scp)) {
2578 sc_set_cursor_image(scp);
2579 sc_draw_cursor_image(scp);
2582 /* save font and palette */
2583 #ifndef SC_NO_FONT_LOADING
2584 sc->fonts_loaded = 0;
2585 if (ISFONTAVAIL(sc->adp->va_flags)) {
2587 bcopy(dflt_font_8, sc->font_8, sizeof(dflt_font_8));
2588 bcopy(dflt_font_14, sc->font_14, sizeof(dflt_font_14));
2589 bcopy(dflt_font_16, sc->font_16, sizeof(dflt_font_16));
2590 sc->fonts_loaded = FONT_16 | FONT_14 | FONT_8;
2591 if (scp->font_size < 14) {
2592 sc_load_font(scp, 0, 8, sc->font_8, 0, 256);
2593 } else if (scp->font_size >= 16) {
2594 sc_load_font(scp, 0, 16, sc->font_16, 0, 256);
2596 sc_load_font(scp, 0, 14, sc->font_14, 0, 256);
2598 #else /* !SC_DFLT_FONT */
2599 if (scp->font_size < 14) {
2600 sc_save_font(scp, 0, 8, sc->font_8, 0, 256);
2601 sc->fonts_loaded = FONT_8;
2602 } else if (scp->font_size >= 16) {
2603 sc_save_font(scp, 0, 16, sc->font_16, 0, 256);
2604 sc->fonts_loaded = FONT_16;
2606 sc_save_font(scp, 0, 14, sc->font_14, 0, 256);
2607 sc->fonts_loaded = FONT_14;
2609 #endif /* SC_DFLT_FONT */
2610 /* FONT KLUDGE: always use the font page #0. XXX */
2611 sc_show_font(scp, 0);
2613 #endif /* !SC_NO_FONT_LOADING */
2615 #ifndef SC_NO_PALETTE_LOADING
2616 save_palette(sc->adp, sc->palette);
2620 if (!(sc->flags & SC_SPLASH_SCRN) && (flags & SC_KERNEL_CONSOLE)) {
2621 /* we are ready to put up the splash image! */
2622 splash_init(sc->adp, scsplash_callback, sc);
2623 sc->flags |= SC_SPLASH_SCRN;
2625 #endif /* NSPLASH */
2628 /* the rest is not necessary, if we have done it once */
2629 if (sc->flags & SC_INIT_DONE)
2632 /* initialize mapscrn arrays to a one to one map */
2633 for (i = 0; i < sizeof(sc->scr_map); i++)
2634 sc->scr_map[i] = sc->scr_rmap[i] = i;
2636 sc->flags |= SC_INIT_DONE;
2640 scterm(int unit, int flags)
2645 sc = sc_get_softc(unit, flags & SC_KERNEL_CONSOLE);
2647 return; /* shouldn't happen */
2650 /* this console is no longer available for the splash screen */
2651 if (sc->flags & SC_SPLASH_SCRN) {
2652 splash_term(sc->adp);
2653 sc->flags &= ~SC_SPLASH_SCRN;
2655 #endif /* NSPLASH */
2658 /* move the hardware cursor to the upper-left corner */
2659 (*vidsw[sc->adapter]->set_hw_cursor)(sc->adp, 0, 0);
2662 /* release the keyboard and the video card */
2663 if (sc->keyboard >= 0)
2664 kbd_release(sc->kbd, &sc->keyboard);
2665 if (sc->adapter >= 0)
2666 vid_release(sc->adp, &sc->adapter);
2668 /* stop the terminal emulator, if any */
2669 scp = SC_STAT(sc->dev[0]);
2671 (*scp->tsw->te_term)(scp, &scp->ts);
2672 if (scp->ts != NULL)
2673 free(scp->ts, M_SYSCONS);
2675 /* clear the structure */
2676 if (!(flags & SC_KERNEL_CONSOLE)) {
2677 /* XXX: We need delete_dev() for this */
2678 free(sc->dev, M_SYSCONS);
2680 /* XXX: We need a ttyunregister for this */
2681 free(sc->tty, M_SYSCONS);
2683 #ifndef SC_NO_FONT_LOADING
2684 free(sc->font_8, M_SYSCONS);
2685 free(sc->font_14, M_SYSCONS);
2686 free(sc->font_16, M_SYSCONS);
2688 /* XXX vtb, history */
2690 bzero(sc, sizeof(*sc));
2696 scshutdown(void *arg, int howto)
2698 /* assert(sc_console != NULL) */
2700 sc_touch_scrn_saver();
2701 if (!cold && sc_console
2702 && sc_console->sc->cur_scp->smode.mode == VT_AUTO
2703 && sc_console->smode.mode == VT_AUTO)
2704 sc_switch_scr(sc_console->sc, sc_console->index);
2705 shutdown_in_progress = TRUE;
2709 sc_clean_up(scr_stat *scp)
2713 #endif /* NSPLASH */
2715 if (scp->sc->flags & SC_SCRN_BLANKED) {
2716 sc_touch_scrn_saver();
2718 if ((error = wait_scrn_saver_stop(scp->sc)))
2720 #endif /* NSPLASH */
2722 scp->status |= MOUSE_HIDDEN;
2723 sc_remove_mouse_image(scp);
2724 sc_remove_cutmarking(scp);
2729 sc_alloc_scr_buffer(scr_stat *scp, int wait, int discard)
2735 sc_vtb_init(&new, VTB_MEMORY, scp->xsize, scp->ysize, NULL, wait);
2736 if (!discard && (old.vtb_flags & VTB_VALID)) {
2737 /* retain the current cursor position and buffer contants */
2738 scp->cursor_oldpos = scp->cursor_pos;
2740 * This works only if the old buffer has the same size as or larger
2741 * than the new one. XXX
2743 sc_vtb_copy(&old, 0, &new, 0, scp->xsize*scp->ysize);
2747 sc_vtb_destroy(&old);
2750 #ifndef SC_NO_SYSMOUSE
2751 /* move the mouse cursor at the center of the screen */
2752 sc_mouse_move(scp, scp->xpixel / 2, scp->ypixel / 2);
2757 alloc_scp(sc_softc_t *sc, int vty)
2761 /* assert(sc_malloc) */
2763 scp = malloc(sizeof(scr_stat), M_SYSCONS, M_WAITOK);
2764 init_scp(sc, vty, scp);
2766 sc_alloc_scr_buffer(scp, TRUE, TRUE);
2767 if (sc_init_emulator(scp, SC_DFLT_TERM))
2768 sc_init_emulator(scp, "*");
2770 #ifndef SC_NO_CUTPASTE
2771 sc_alloc_cut_buffer(scp, TRUE);
2774 #ifndef SC_NO_HISTORY
2775 sc_alloc_history_buffer(scp, 0, 0, TRUE);
2782 init_scp(sc_softc_t *sc, int vty, scr_stat *scp)
2786 bzero(scp, sizeof(*scp));
2791 scp->mode = sc->initial_mode;
2792 callout_init(&scp->blink_screen_ch);
2793 (*vidsw[sc->adapter]->get_info)(sc->adp, scp->mode, &info);
2794 if (info.vi_flags & V_INFO_GRAPHICS) {
2795 scp->status |= GRAPHICS_MODE;
2796 scp->xpixel = info.vi_width;
2797 scp->ypixel = info.vi_height;
2798 scp->xsize = info.vi_width/8;
2799 scp->ysize = info.vi_height/info.vi_cheight;
2803 scp->xsize = info.vi_width;
2804 scp->ysize = info.vi_height;
2805 scp->xpixel = scp->xsize*8;
2806 scp->ypixel = scp->ysize*info.vi_cheight;
2807 if (info.vi_cheight < 14) {
2809 #ifndef SC_NO_FONT_LOADING
2810 scp->font = sc->font_8;
2814 } else if (info.vi_cheight >= 16) {
2815 scp->font_size = 16;
2816 #ifndef SC_NO_FONT_LOADING
2817 scp->font = sc->font_16;
2822 scp->font_size = 14;
2823 #ifndef SC_NO_FONT_LOADING
2824 scp->font = sc->font_14;
2830 sc_vtb_init(&scp->vtb, VTB_MEMORY, 0, 0, NULL, FALSE);
2831 sc_vtb_init(&scp->scr, VTB_FRAMEBUFFER, 0, 0, NULL, FALSE);
2832 scp->xoff = scp->yoff = 0;
2833 scp->xpos = scp->ypos = 0;
2834 scp->start = scp->xsize * scp->ysize - 1;
2839 scp->border = BG_BLACK;
2840 scp->cursor_base = sc->cursor_base;
2841 scp->cursor_height = imin(sc->cursor_height, scp->font_size);
2842 scp->mouse_cut_start = scp->xsize*scp->ysize;
2843 scp->mouse_cut_end = -1;
2844 scp->mouse_signal = 0;
2846 scp->mouse_proc = NULL;
2847 scp->kbd_mode = K_XLATE;
2848 scp->bell_pitch = bios_value.bell_pitch;
2849 scp->bell_duration = BELL_DURATION;
2850 scp->status |= (bios_value.shift_state & NLKED);
2851 scp->status |= CURSOR_ENABLED | MOUSE_HIDDEN;
2854 scp->smode.mode = VT_AUTO;
2855 scp->history = NULL;
2856 scp->history_pos = 0;
2857 scp->history_size = 0;
2861 sc_init_emulator(scr_stat *scp, char *name)
2868 if (name == NULL) /* if no name is given, use the current emulator */
2870 else /* ...otherwise find the named emulator */
2871 sw = sc_term_match(name);
2876 if (strcmp(sw->te_renderer, "*") != 0) {
2877 rndr = sc_render_match(scp, sw->te_renderer,
2878 scp->status & (GRAPHICS_MODE | PIXEL_MODE));
2881 rndr = sc_render_match(scp, scp->sc->adp->va_name,
2882 scp->status & (GRAPHICS_MODE | PIXEL_MODE));
2887 if (sw == scp->tsw) {
2888 error = (*sw->te_init)(scp, &scp->ts, SC_TE_WARM_INIT);
2890 scp->rndr->init(scp);
2891 sc_clear_screen(scp);
2892 /* assert(error == 0); */
2896 if (sc_malloc && (sw->te_size > 0))
2897 p = malloc(sw->te_size, M_SYSCONS, M_NOWAIT);
2900 error = (*sw->te_init)(scp, &p, SC_TE_COLD_INIT);
2905 (*scp->tsw->te_term)(scp, &scp->ts);
2906 if (scp->ts != NULL)
2907 free(scp->ts, M_SYSCONS);
2911 scp->rndr->init(scp);
2914 (*sw->te_default_attr)(scp, user_default.std_color, user_default.rev_color);
2915 sc_clear_screen(scp);
2921 * scgetc(flags) - get character from keyboard.
2922 * If flags & SCGETC_CN, then avoid harmful side effects.
2923 * If flags & SCGETC_NONBLOCK, then wait until a key is pressed, else
2924 * return NOKEY if there is nothing there.
2927 scgetc(sc_softc_t *sc, u_int flags)
2930 #ifndef SC_NO_HISTORY
2938 if (sc->kbd == NULL)
2943 /* I don't like this, but... XXX */
2944 if (flags & SCGETC_CN)
2945 sccnupdate(sc->cur_scp);
2948 /* first see if there is something in the keyboard port */
2950 c = kbd_read_char(sc->kbd, !(flags & SCGETC_NONBLOCK));
2952 if (!(flags & SCGETC_CN))
2953 sc_bell(scp, bios_value.bell_pitch, BELL_DURATION);
2954 } else if (c == NOKEY)
2960 /* make screensaver happy */
2962 sc_touch_scrn_saver();
2964 if (!(flags & SCGETC_CN))
2965 /* do the /dev/random device a favour */
2966 add_keyboard_randomness(c);
2968 if (scp->kbd_mode != K_XLATE)
2971 /* if scroll-lock pressed allow history browsing */
2972 if (!ISGRAPHSC(scp) && scp->history && scp->status & SLKED) {
2974 scp->status &= ~CURSOR_ENABLED;
2975 sc_remove_cursor_image(scp);
2977 #ifndef SC_NO_HISTORY
2978 if (!(scp->status & BUFFER_SAVED)) {
2979 scp->status |= BUFFER_SAVED;
2983 /* FIXME: key codes */
2984 case SPCLKEY | FKEY | F(49): /* home key */
2985 sc_remove_cutmarking(scp);
2989 case SPCLKEY | FKEY | F(57): /* end key */
2990 sc_remove_cutmarking(scp);
2994 case SPCLKEY | FKEY | F(50): /* up arrow key */
2995 sc_remove_cutmarking(scp);
2996 if (sc_hist_up_line(scp))
2997 if (!(flags & SCGETC_CN))
2998 sc_bell(scp, bios_value.bell_pitch, BELL_DURATION);
3001 case SPCLKEY | FKEY | F(58): /* down arrow key */
3002 sc_remove_cutmarking(scp);
3003 if (sc_hist_down_line(scp))
3004 if (!(flags & SCGETC_CN))
3005 sc_bell(scp, bios_value.bell_pitch, BELL_DURATION);
3008 case SPCLKEY | FKEY | F(51): /* page up key */
3009 sc_remove_cutmarking(scp);
3010 for (i=0; i<scp->ysize; i++)
3011 if (sc_hist_up_line(scp)) {
3012 if (!(flags & SCGETC_CN))
3013 sc_bell(scp, bios_value.bell_pitch, BELL_DURATION);
3018 case SPCLKEY | FKEY | F(59): /* page down key */
3019 sc_remove_cutmarking(scp);
3020 for (i=0; i<scp->ysize; i++)
3021 if (sc_hist_down_line(scp)) {
3022 if (!(flags & SCGETC_CN))
3023 sc_bell(scp, bios_value.bell_pitch, BELL_DURATION);
3028 #endif /* SC_NO_HISTORY */
3032 * Process and consume special keys here. Return a plain char code
3033 * or a char code with the META flag or a function key code.
3037 /* goto next_code */
3042 switch (KEYCHAR(c)) {
3044 case NLK: case CLK: case ALK:
3047 kbd_ioctl(sc->kbd, KDGKBSTATE, (caddr_t)&f);
3049 scp->status |= SLKED;
3051 if (scp->status & SLKED) {
3052 scp->status &= ~SLKED;
3053 #ifndef SC_NO_HISTORY
3054 if (scp->status & BUFFER_SAVED) {
3055 if (!sc_hist_restore(scp))
3056 sc_remove_cutmarking(scp);
3057 scp->status &= ~BUFFER_SAVED;
3058 scp->status |= CURSOR_ENABLED;
3059 sc_draw_cursor_image(scp);
3061 tp = VIRTUAL_TTY(sc, scp->index);
3069 /* NON-LOCKING KEYS */
3071 case LSH: case RSH: case LCTR: case RCTR:
3072 case LALT: case RALT: case ASH: case META:
3076 if (!(sc->flags & SC_SCRN_BLANKED))
3082 /* force activatation/deactivation of the screen saver */
3083 if (!(sc->flags & SC_SCRN_BLANKED)) {
3084 run_scrn_saver = TRUE;
3085 sc->scrn_time_stamp -= scrn_blank_time;
3089 * While devices are being probed, the screen saver need
3090 * to be invoked explictly. XXX
3092 if (sc->flags & SC_SCRN_BLANKED) {
3093 scsplash_stick(FALSE);
3094 stop_scrn_saver(sc, current_saver);
3096 if (!ISGRAPHSC(scp)) {
3097 scsplash_stick(TRUE);
3098 (*current_saver)(sc, TRUE);
3102 #endif /* NSPLASH */
3106 #ifndef SC_DISABLE_REBOOT
3112 #ifndef SC_DISABLE_REBOOT
3113 shutdown_nice(RB_HALT);
3118 #ifndef SC_DISABLE_REBOOT
3119 shutdown_nice(RB_HALT|RB_POWEROFF);
3125 apm_suspend(PMST_SUSPEND);
3128 apm_suspend(PMST_STANDBY);
3137 #ifndef SC_DISABLE_DDBKEY
3139 Debugger("manual escape to debugger");
3141 printf("No debugger in kernel\n");
3143 #else /* SC_DISABLE_DDBKEY */
3145 #endif /* SC_DISABLE_DDBKEY */
3149 if (enable_panic_key)
3150 panic("Forced by the panic key");
3154 this_scr = scp->index;
3155 for (i = (this_scr - sc->first_vty + 1)%sc->vtys;
3156 sc->first_vty + i != this_scr;
3157 i = (i + 1)%sc->vtys) {
3158 struct tty *tp = VIRTUAL_TTY(sc, sc->first_vty + i);
3159 if (ISTTYOPEN(tp)) {
3160 sc_switch_scr(scp->sc, sc->first_vty + i);
3167 this_scr = scp->index;
3168 for (i = (this_scr - sc->first_vty + sc->vtys - 1)%sc->vtys;
3169 sc->first_vty + i != this_scr;
3170 i = (i + sc->vtys - 1)%sc->vtys) {
3171 struct tty *tp = VIRTUAL_TTY(sc, sc->first_vty + i);
3172 if (ISTTYOPEN(tp)) {
3173 sc_switch_scr(scp->sc, sc->first_vty + i);
3180 if (KEYCHAR(c) >= F_SCR && KEYCHAR(c) <= L_SCR) {
3181 sc_switch_scr(scp->sc, sc->first_vty + KEYCHAR(c) - F_SCR);
3184 /* assert(c & FKEY) */
3185 if (!(sc->flags & SC_SCRN_BLANKED))
3189 /* goto next_code */
3191 /* regular keys (maybe MKEY is set) */
3192 if (!(sc->flags & SC_SCRN_BLANKED))
3201 scmmap(dev_t dev, vm_offset_t offset, int nprot)
3206 if (scp != scp->sc->cur_scp)
3208 return (*vidsw[scp->sc->adapter]->mmap)(scp->sc->adp, offset, nprot);
3212 save_kbd_state(scr_stat *scp)
3217 error = kbd_ioctl(scp->sc->kbd, KDGKBSTATE, (caddr_t)&state);
3218 if (error == ENOIOCTL)
3221 scp->status &= ~LOCK_MASK;
3222 scp->status |= state;
3228 update_kbd_state(scr_stat *scp, int new_bits, int mask)
3233 if (mask != LOCK_MASK) {
3234 error = kbd_ioctl(scp->sc->kbd, KDGKBSTATE, (caddr_t)&state);
3235 if (error == ENOIOCTL)
3240 state |= new_bits & mask;
3242 state = new_bits & LOCK_MASK;
3244 error = kbd_ioctl(scp->sc->kbd, KDSKBSTATE, (caddr_t)&state);
3245 if (error == ENOIOCTL)
3251 update_kbd_leds(scr_stat *scp, int which)
3256 error = kbd_ioctl(scp->sc->kbd, KDSETLED, (caddr_t)&which);
3257 if (error == ENOIOCTL)
3263 set_mode(scr_stat *scp)
3267 /* reject unsupported mode */
3268 if ((*vidsw[scp->sc->adapter]->get_info)(scp->sc->adp, scp->mode, &info))
3271 /* if this vty is not currently showing, do nothing */
3272 if (scp != scp->sc->cur_scp)
3275 /* setup video hardware for the given mode */
3276 (*vidsw[scp->sc->adapter]->set_mode)(scp->sc->adp, scp->mode);
3277 scp->rndr->init(scp);
3278 sc_vtb_init(&scp->scr, VTB_FRAMEBUFFER, scp->xsize, scp->ysize,
3279 (void *)scp->sc->adp->va_window, FALSE);
3281 #ifndef SC_NO_FONT_LOADING
3282 /* load appropriate font */
3283 if (!(scp->status & GRAPHICS_MODE)) {
3284 if (!(scp->status & PIXEL_MODE) && ISFONTAVAIL(scp->sc->adp->va_flags)) {
3285 if (scp->font_size < 14) {
3286 if (scp->sc->fonts_loaded & FONT_8)
3287 sc_load_font(scp, 0, 8, scp->sc->font_8, 0, 256);
3288 } else if (scp->font_size >= 16) {
3289 if (scp->sc->fonts_loaded & FONT_16)
3290 sc_load_font(scp, 0, 16, scp->sc->font_16, 0, 256);
3292 if (scp->sc->fonts_loaded & FONT_14)
3293 sc_load_font(scp, 0, 14, scp->sc->font_14, 0, 256);
3297 * This is an interim kludge to display correct font.
3298 * Always use the font page #0 on the video plane 2.
3299 * Somehow we cannot show the font in other font pages on
3300 * some video cards... XXX
3302 sc_show_font(scp, 0);
3306 #endif /* !SC_NO_FONT_LOADING */
3308 sc_set_border(scp, scp->border);
3309 sc_set_cursor_image(scp);
3315 refresh_ega_palette(scr_stat *scp)
3319 int rsize, gsize, bsize;
3320 int rfld, gfld, bfld;
3323 rsize = scp->sc->adp->va_info.vi_pixel_fsizes[0];
3324 gsize = scp->sc->adp->va_info.vi_pixel_fsizes[1];
3325 bsize = scp->sc->adp->va_info.vi_pixel_fsizes[2];
3326 rfld = scp->sc->adp->va_info.vi_pixel_fields[0];
3327 gfld = scp->sc->adp->va_info.vi_pixel_fields[1];
3328 bfld = scp->sc->adp->va_info.vi_pixel_fields[2];
3330 for (i = 0; i < 16; i++) {
3331 reg = scp->sc->adp->va_palette_regs[i];
3333 r = scp->sc->palette[reg * 3] >> (8 - rsize);
3334 g = scp->sc->palette[reg * 3 + 1] >> (8 - gsize);
3335 b = scp->sc->palette[reg * 3 + 2] >> (8 - bsize);
3337 scp->ega_palette[i] = (r << rfld) + (g << gfld) + (b << bfld);
3342 sc_set_border(scr_stat *scp, int color)
3344 ++scp->sc->videoio_in_progress;
3345 (*scp->rndr->draw_border)(scp, color);
3346 --scp->sc->videoio_in_progress;
3349 #ifndef SC_NO_FONT_LOADING
3351 sc_load_font(scr_stat *scp, int page, int size, u_char *buf,
3352 int base, int count)
3357 sc->font_loading_in_progress = TRUE;
3358 (*vidsw[sc->adapter]->load_font)(sc->adp, page, size, buf, base, count);
3359 sc->font_loading_in_progress = FALSE;
3363 sc_save_font(scr_stat *scp, int page, int size, u_char *buf,
3364 int base, int count)
3369 sc->font_loading_in_progress = TRUE;
3370 (*vidsw[sc->adapter]->save_font)(sc->adp, page, size, buf, base, count);
3371 sc->font_loading_in_progress = FALSE;
3375 sc_show_font(scr_stat *scp, int page)
3377 (*vidsw[scp->sc->adapter]->show_font)(scp->sc->adp, page);
3379 #endif /* !SC_NO_FONT_LOADING */
3382 sc_paste(scr_stat *scp, u_char *p, int count)
3387 if (scp->status & MOUSE_VISIBLE) {
3388 tp = VIRTUAL_TTY(scp->sc, scp->sc->cur_scp->index);
3391 rmap = scp->sc->scr_rmap;
3392 for (; count > 0; --count)
3393 (*linesw[tp->t_line].l_rint)(rmap[*p++], tp);
3398 sc_bell(scr_stat *scp, int pitch, int duration)
3400 if (cold || shutdown_in_progress)
3403 if (scp != scp->sc->cur_scp && (scp->sc->flags & SC_QUIET_BELL))
3406 if (scp->sc->flags & SC_VISUAL_BELL) {
3407 if (scp->sc->blink_in_progress)
3409 scp->sc->blink_in_progress = 3;
3410 if (scp != scp->sc->cur_scp)
3411 scp->sc->blink_in_progress += 2;
3412 blink_screen(scp->sc->cur_scp);
3413 } else if (duration != 0 && pitch != 0) {
3414 if (scp != scp->sc->cur_scp)
3416 sysbeep(pitch, duration);
3421 blink_screen(void *arg)
3423 scr_stat *scp = arg;
3426 if (ISGRAPHSC(scp) || (scp->sc->blink_in_progress <= 1)) {
3427 scp->sc->blink_in_progress = 0;
3429 tp = VIRTUAL_TTY(scp->sc, scp->index);
3432 if (scp->sc->delayed_next_scr)
3433 sc_switch_scr(scp->sc, scp->sc->delayed_next_scr - 1);
3436 (*scp->rndr->draw)(scp, 0, scp->xsize*scp->ysize,
3437 scp->sc->blink_in_progress & 1);
3438 scp->sc->blink_in_progress--;
3439 callout_reset(&scp->blink_screen_ch, hz / 10, blink_screen, scp);