31 32#include "opt_syscons.h" 33#include "opt_splash.h" 34#include "opt_ddb.h" 35 36#include <sys/param.h> 37#include <sys/systm.h> 38#include <sys/conf.h> 39#include <sys/cons.h> 40#include <sys/consio.h> 41#include <sys/eventhandler.h> 42#include <sys/fbio.h> 43#include <sys/kbio.h> 44#include <sys/kernel.h> 45#include <sys/lock.h> 46#include <sys/malloc.h> 47#include <sys/mutex.h> 48#include <sys/proc.h> 49#include <sys/random.h> 50#include <sys/reboot.h> 51#include <sys/signalvar.h> 52#include <sys/sysctl.h> 53#include <sys/tty.h> 54#include <sys/power.h> 55 56#include <machine/clock.h> 57#if __sparc64__ || __powerpc__ 58#include <machine/sc_machdep.h> 59#else 60#include <machine/pc/display.h> 61#endif 62#ifdef __i386__ 63#include <machine/psl.h> 64#include <machine/apm_bios.h> 65#include <machine/frame.h> 66#endif 67 68#include <dev/kbd/kbdreg.h> 69#include <dev/fb/fbreg.h> 70#include <dev/fb/splashreg.h> 71#include <dev/syscons/syscons.h> 72 73#define COLD 0 74#define WARM 1 75 76#define DEFAULT_BLANKTIME (5*60) /* 5 minutes */ 77#define MAX_BLANKTIME (7*24*60*60) /* 7 days!? */ 78 79#define KEYCODE_BS 0x0e /* "<-- Backspace" key, XXX */ 80 81typedef struct default_attr { 82 int std_color; /* normal hardware color */ 83 int rev_color; /* reverse hardware color */ 84} default_attr; 85 86static default_attr user_default = { 87 SC_NORM_ATTR, 88 SC_NORM_REV_ATTR, 89}; 90 91static default_attr kernel_default = { 92 SC_KERNEL_CONS_ATTR, 93 SC_KERNEL_CONS_REV_ATTR, 94}; 95 96static int sc_console_unit = -1; 97static int sc_saver_keyb_only = 1; 98static scr_stat *sc_console; 99static struct tty *sc_console_tty; 100static struct consdev *sc_consptr; 101static void *kernel_console_ts; 102static scr_stat main_console; 103static struct cdev *main_devs[MAXCONS]; 104 105static char init_done = COLD; 106static char shutdown_in_progress = FALSE; 107static char sc_malloc = FALSE; 108 109static int saver_mode = CONS_NO_SAVER; /* LKM/user saver */ 110static int run_scrn_saver = FALSE; /* should run the saver? */ 111static int enable_bell = TRUE; /* enable beeper */ 112static long scrn_blank_time = 0; /* screen saver timeout value */ 113#ifdef DEV_SPLASH 114static int scrn_blanked; /* # of blanked screen */ 115static int sticky_splash = FALSE; 116 117static void none_saver(sc_softc_t *sc, int blank) { } 118static void (*current_saver)(sc_softc_t *, int) = none_saver; 119#endif 120 121SYSCTL_NODE(_hw, OID_AUTO, syscons, CTLFLAG_RD, 0, "syscons"); 122SYSCTL_NODE(_hw_syscons, OID_AUTO, saver, CTLFLAG_RD, 0, "saver"); 123SYSCTL_INT(_hw_syscons_saver, OID_AUTO, keybonly, CTLFLAG_RW, 124 &sc_saver_keyb_only, 0, "screen saver interrupted by input only"); 125SYSCTL_INT(_hw_syscons, OID_AUTO, bell, CTLFLAG_RW, &enable_bell, 126 0, "enable bell"); 127#if !defined(SC_NO_FONT_LOADING) && defined(SC_DFLT_FONT) 128#include "font.h" 129#endif 130 131 d_ioctl_t *sc_user_ioctl; 132 133static bios_values_t bios_value; 134 135static int enable_panic_key; 136SYSCTL_INT(_machdep, OID_AUTO, enable_panic_key, CTLFLAG_RW, &enable_panic_key, 137 0, ""); 138 139#define SC_CONSOLECTL 255 140 141#define VIRTUAL_TTY(sc, x) (SC_DEV((sc), (x)) != NULL ? \ 142 SC_DEV((sc), (x))->si_tty : NULL) 143#define ISTTYOPEN(tp) ((tp) && ((tp)->t_state & TS_ISOPEN)) 144 145static int debugger; 146 147/* prototypes */ 148static int scvidprobe(int unit, int flags, int cons); 149static int sckbdprobe(int unit, int flags, int cons); 150static void scmeminit(void *arg); 151static int scdevtounit(struct cdev *dev); 152static kbd_callback_func_t sckbdevent; 153static int scparam(struct tty *tp, struct termios *t); 154static void scstart(struct tty *tp); 155static void scinit(int unit, int flags); 156static scr_stat *sc_get_stat(struct cdev *devptr); 157#if !__alpha__ 158static void scterm(int unit, int flags); 159#endif 160static void scshutdown(void *arg, int howto); 161static u_int scgetc(sc_softc_t *sc, u_int flags); 162#define SCGETC_CN 1 163#define SCGETC_NONBLOCK 2 164static int sccngetch(int flags); 165static void sccnupdate(scr_stat *scp); 166static scr_stat *alloc_scp(sc_softc_t *sc, int vty); 167static void init_scp(sc_softc_t *sc, int vty, scr_stat *scp); 168static timeout_t scrn_timer; 169static int and_region(int *s1, int *e1, int s2, int e2); 170static void scrn_update(scr_stat *scp, int show_cursor); 171 172#ifdef DEV_SPLASH 173static int scsplash_callback(int event, void *arg); 174static void scsplash_saver(sc_softc_t *sc, int show); 175static int add_scrn_saver(void (*this_saver)(sc_softc_t *, int)); 176static int remove_scrn_saver(void (*this_saver)(sc_softc_t *, int)); 177static int set_scrn_saver_mode(scr_stat *scp, int mode, u_char *pal, int border); 178static int restore_scrn_saver_mode(scr_stat *scp, int changemode); 179static void stop_scrn_saver(sc_softc_t *sc, void (*saver)(sc_softc_t *, int)); 180static int wait_scrn_saver_stop(sc_softc_t *sc); 181#define scsplash_stick(stick) (sticky_splash = (stick)) 182#else /* !DEV_SPLASH */ 183#define scsplash_stick(stick) 184#endif /* DEV_SPLASH */ 185 186static int do_switch_scr(sc_softc_t *sc, int s); 187static int vt_proc_alive(scr_stat *scp); 188static int signal_vt_rel(scr_stat *scp); 189static int signal_vt_acq(scr_stat *scp); 190static int finish_vt_rel(scr_stat *scp, int release, int *s); 191static int finish_vt_acq(scr_stat *scp); 192static void exchange_scr(sc_softc_t *sc); 193static void update_cursor_image(scr_stat *scp); 194static void change_cursor_shape(scr_stat *scp, int flags, int base, int height); 195static int save_kbd_state(scr_stat *scp); 196static int update_kbd_state(scr_stat *scp, int state, int mask); 197static int update_kbd_leds(scr_stat *scp, int which); 198static timeout_t blink_screen; 199 200static cn_probe_t sccnprobe; 201static cn_init_t sccninit; 202static cn_getc_t sccngetc; 203static cn_checkc_t sccncheckc; 204static cn_putc_t sccnputc; 205static cn_dbctl_t sccndbctl; 206static cn_term_t sccnterm; 207 208#if __alpha__ 209void sccnattach(void); 210#endif 211 212CONS_DRIVER(sc, sccnprobe, sccninit, sccnterm, sccngetc, sccncheckc, sccnputc, 213 sccndbctl); 214 215static d_open_t scopen; 216static d_close_t scclose; 217static d_read_t scread; 218static d_ioctl_t scioctl; 219static d_mmap_t scmmap; 220 221static struct cdevsw sc_cdevsw = { 222 .d_version = D_VERSION, 223 .d_open = scopen, 224 .d_close = scclose, 225 .d_read = scread, 226 .d_ioctl = scioctl, 227 .d_mmap = scmmap, 228 .d_name = "sc", 229 .d_flags = D_TTY | D_NEEDGIANT, 230}; 231 232int 233sc_probe_unit(int unit, int flags) 234{ 235 if (!scvidprobe(unit, flags, FALSE)) { 236 if (bootverbose) 237 printf("sc%d: no video adapter found.\n", unit); 238 return ENXIO; 239 } 240 241 /* syscons will be attached even when there is no keyboard */ 242 sckbdprobe(unit, flags, FALSE); 243 244 return 0; 245} 246 247/* probe video adapters, return TRUE if found */ 248static int 249scvidprobe(int unit, int flags, int cons) 250{ 251 /* 252 * Access the video adapter driver through the back door! 253 * Video adapter drivers need to be configured before syscons. 254 * However, when syscons is being probed as the low-level console, 255 * they have not been initialized yet. We force them to initialize 256 * themselves here. XXX 257 */ 258 vid_configure(cons ? VIO_PROBE_ONLY : 0); 259 260 return (vid_find_adapter("*", unit) >= 0); 261} 262 263/* probe the keyboard, return TRUE if found */ 264static int 265sckbdprobe(int unit, int flags, int cons) 266{ 267 /* access the keyboard driver through the backdoor! */ 268 kbd_configure(cons ? KB_CONF_PROBE_ONLY : 0); 269 270 return (kbd_find_keyboard("*", unit) >= 0); 271} 272 273static char 274*adapter_name(video_adapter_t *adp) 275{ 276 static struct { 277 int type; 278 char *name[2]; 279 } names[] = { 280 { KD_MONO, { "MDA", "MDA" } }, 281 { KD_HERCULES, { "Hercules", "Hercules" } }, 282 { KD_CGA, { "CGA", "CGA" } }, 283 { KD_EGA, { "EGA", "EGA (mono)" } }, 284 { KD_VGA, { "VGA", "VGA (mono)" } }, 285 { KD_PC98, { "PC-98x1", "PC-98x1" } }, 286 { KD_TGA, { "TGA", "TGA" } }, 287 { -1, { "Unknown", "Unknown" } }, 288 }; 289 int i; 290 291 for (i = 0; names[i].type != -1; ++i) 292 if (names[i].type == adp->va_type) 293 break; 294 return names[i].name[(adp->va_flags & V_ADP_COLOR) ? 0 : 1]; 295} 296 297int 298sc_attach_unit(int unit, int flags) 299{ 300 sc_softc_t *sc; 301 scr_stat *scp; 302#ifdef SC_PIXEL_MODE 303 video_info_t info; 304#endif 305 int vc; 306 struct cdev *dev; 307 308 flags &= ~SC_KERNEL_CONSOLE; 309 310 if (sc_console_unit == unit) { 311 /* 312 * If this unit is being used as the system console, we need to 313 * adjust some variables and buffers before and after scinit(). 314 */ 315 /* assert(sc_console != NULL) */ 316 flags |= SC_KERNEL_CONSOLE; 317 scmeminit(NULL); 318 319 scinit(unit, flags); 320 321 if (sc_console->tsw->te_size > 0) { 322 /* assert(sc_console->ts != NULL); */ 323 kernel_console_ts = sc_console->ts; 324 sc_console->ts = malloc(sc_console->tsw->te_size, 325 M_DEVBUF, M_WAITOK); 326 bcopy(kernel_console_ts, sc_console->ts, sc_console->tsw->te_size); 327 (*sc_console->tsw->te_default_attr)(sc_console, 328 user_default.std_color, 329 user_default.rev_color); 330 } 331 } else { 332 scinit(unit, flags); 333 } 334 335 sc = sc_get_softc(unit, flags & SC_KERNEL_CONSOLE); 336 sc->config = flags; 337 scp = sc_get_stat(sc->dev[0]); 338 if (sc_console == NULL) /* sc_console_unit < 0 */ 339 sc_console = scp; 340 341#ifdef SC_PIXEL_MODE 342 if ((sc->config & SC_VESA800X600) 343 && ((*vidsw[sc->adapter]->get_info)(sc->adp, M_VESA_800x600, &info) == 0)) { 344#ifdef DEV_SPLASH 345 if (sc->flags & SC_SPLASH_SCRN) 346 splash_term(sc->adp); 347#endif 348 sc_set_graphics_mode(scp, NULL, M_VESA_800x600); 349 sc_set_pixel_mode(scp, NULL, COL, ROW, 16); 350 sc->initial_mode = M_VESA_800x600; 351#ifdef DEV_SPLASH 352 /* put up the splash again! */ 353 if (sc->flags & SC_SPLASH_SCRN) 354 splash_init(sc->adp, scsplash_callback, sc); 355#endif 356 } 357#endif /* SC_PIXEL_MODE */ 358 359 /* initialize cursor */ 360 if (!ISGRAPHSC(scp)) 361 update_cursor_image(scp); 362 363 /* get screen update going */ 364 scrn_timer(sc); 365 366 /* set up the keyboard */ 367 kbd_ioctl(sc->kbd, KDSKBMODE, (caddr_t)&scp->kbd_mode); 368 update_kbd_state(scp, scp->status, LOCK_MASK); 369 370 printf("sc%d: %s <%d virtual consoles, flags=0x%x>\n", 371 unit, adapter_name(sc->adp), sc->vtys, sc->config); 372 if (bootverbose) { 373 printf("sc%d:", unit); 374 if (sc->adapter >= 0) 375 printf(" fb%d", sc->adapter); 376 if (sc->keyboard >= 0) 377 printf(", kbd%d", sc->keyboard); 378 if (scp->tsw) 379 printf(", terminal emulator: %s (%s)", 380 scp->tsw->te_name, scp->tsw->te_desc); 381 printf("\n"); 382 } 383 384 /* register a shutdown callback for the kernel console */ 385 if (sc_console_unit == unit) 386 EVENTHANDLER_REGISTER(shutdown_pre_sync, scshutdown, 387 (void *)(uintptr_t)unit, SHUTDOWN_PRI_DEFAULT); 388 389 for (vc = 0; vc < sc->vtys; vc++) { 390 if (sc->dev[vc] == NULL) { 391 dev = make_dev(&sc_cdevsw, vc + unit * MAXCONS, 392 UID_ROOT, GID_WHEEL, 0600, "ttyv%r", vc + unit * MAXCONS); 393 sc->dev[vc] = dev; 394 sc->dev[vc]->si_tty = ttymalloc(sc->dev[vc]->si_tty); 395 if (vc == 0 && sc->dev == main_devs) 396 SC_STAT(sc->dev[0]) = &main_console; 397 } 398 /* 399 * The first vty already has struct tty and scr_stat initialized 400 * in scinit(). The other vtys will have these structs when 401 * first opened. 402 */ 403 } 404 405 dev = make_dev(&sc_cdevsw, SC_CONSOLECTL, 406 UID_ROOT, GID_WHEEL, 0600, "consolectl"); 407 dev->si_tty = sc_console_tty = ttymalloc(sc_console_tty); 408 SC_STAT(dev) = sc_console; 409 410 return 0; 411} 412 413static void 414scmeminit(void *arg) 415{ 416 if (sc_malloc) 417 return; 418 sc_malloc = TRUE; 419 420 /* 421 * As soon as malloc() becomes functional, we had better allocate 422 * various buffers for the kernel console. 423 */ 424 425 if (sc_console_unit < 0) /* sc_console == NULL */ 426 return; 427 428 /* copy the temporary buffer to the final buffer */ 429 sc_alloc_scr_buffer(sc_console, FALSE, FALSE); 430 431#ifndef SC_NO_CUTPASTE 432 sc_alloc_cut_buffer(sc_console, FALSE); 433#endif 434 435#ifndef SC_NO_HISTORY 436 /* initialize history buffer & pointers */ 437 sc_alloc_history_buffer(sc_console, 0, 0, FALSE); 438#endif 439} 440 441/* XXX */ 442SYSINIT(sc_mem, SI_SUB_KMEM, SI_ORDER_ANY, scmeminit, NULL); 443 444static int 445scdevtounit(struct cdev *dev) 446{ 447 int vty = SC_VTY(dev); 448 449 if (vty == SC_CONSOLECTL) 450 return ((sc_console != NULL) ? sc_console->sc->unit : -1); 451 else if ((vty < 0) || (vty >= MAXCONS*sc_max_unit())) 452 return -1; 453 else 454 return vty/MAXCONS; 455} 456 457static int 458scopen(struct cdev *dev, int flag, int mode, struct thread *td) 459{ 460 int unit = scdevtounit(dev); 461 sc_softc_t *sc; 462 struct tty *tp; 463 scr_stat *scp; 464#ifndef __sparc64__ 465 keyarg_t key; 466#endif 467 int error; 468 469 DPRINTF(5, ("scopen: dev:%d,%d, unit:%d, vty:%d\n", 470 major(dev), minor(dev), unit, SC_VTY(dev))); 471 472 sc = sc_get_softc(unit, (sc_console_unit == unit) ? SC_KERNEL_CONSOLE : 0); 473 if (sc == NULL) 474 return ENXIO; 475 476 tp = dev->si_tty = ttymalloc(dev->si_tty); 477 tp->t_oproc = scstart; 478 tp->t_param = scparam; 479 tp->t_stop = nottystop; 480 tp->t_dev = dev; 481 if (!ISTTYOPEN(tp)) { 482 ttychars(tp); 483 /* Use the current setting of the <-- key as default VERASE. */ 484 /* If the Delete key is preferable, an stty is necessary */ 485#ifndef __sparc64__ 486 if (sc->kbd != NULL) { 487 key.keynum = KEYCODE_BS; 488 kbd_ioctl(sc->kbd, GIO_KEYMAPENT, (caddr_t)&key); 489 tp->t_cc[VERASE] = key.key.map[0]; 490 } 491#endif 492 tp->t_iflag = TTYDEF_IFLAG; 493 tp->t_oflag = TTYDEF_OFLAG; 494 tp->t_cflag = TTYDEF_CFLAG; 495 tp->t_lflag = TTYDEF_LFLAG; 496 tp->t_ispeed = tp->t_ospeed = TTYDEF_SPEED; 497 scparam(tp, &tp->t_termios); 498 ttyld_modem(tp, 1); 499 } 500 else 501 if (tp->t_state & TS_XCLUDE && suser(td)) 502 return(EBUSY); 503 504 error = ttyld_open(tp, dev); 505 506 scp = sc_get_stat(dev); 507 if (scp == NULL) { 508 scp = SC_STAT(dev) = alloc_scp(sc, SC_VTY(dev)); 509 if (ISGRAPHSC(scp)) 510 sc_set_pixel_mode(scp, NULL, COL, ROW, 16); 511 } 512 if (!tp->t_winsize.ws_col && !tp->t_winsize.ws_row) { 513 tp->t_winsize.ws_col = scp->xsize; 514 tp->t_winsize.ws_row = scp->ysize; 515 } 516 517 return error; 518} 519 520static int 521scclose(struct cdev *dev, int flag, int mode, struct thread *td) 522{ 523 struct tty *tp = dev->si_tty; 524 scr_stat *scp; 525 int s; 526 527 if (SC_VTY(dev) != SC_CONSOLECTL) { 528 scp = sc_get_stat(tp->t_dev); 529 /* were we in the middle of the VT switching process? */ 530 DPRINTF(5, ("sc%d: scclose(), ", scp->sc->unit)); 531 s = spltty(); 532 if ((scp == scp->sc->cur_scp) && (scp->sc->unit == sc_console_unit)) 533 cnavailable(sc_consptr, TRUE); 534 if (finish_vt_rel(scp, TRUE, &s) == 0) /* force release */ 535 DPRINTF(5, ("reset WAIT_REL, ")); 536 if (finish_vt_acq(scp) == 0) /* force acknowledge */ 537 DPRINTF(5, ("reset WAIT_ACQ, ")); 538#if not_yet_done 539 if (scp == &main_console) { 540 scp->pid = 0; 541 scp->proc = NULL; 542 scp->smode.mode = VT_AUTO; 543 } 544 else { 545 sc_vtb_destroy(&scp->vtb); 546#ifndef __sparc64__ 547 sc_vtb_destroy(&scp->scr); 548#endif 549 sc_free_history_buffer(scp, scp->ysize); 550 SC_STAT(dev) = NULL; 551 free(scp, M_DEVBUF); 552 } 553#else 554 scp->pid = 0; 555 scp->proc = NULL; 556 scp->smode.mode = VT_AUTO; 557#endif 558 scp->kbd_mode = K_XLATE; 559 if (scp == scp->sc->cur_scp) 560 kbd_ioctl(scp->sc->kbd, KDSKBMODE, (caddr_t)&scp->kbd_mode); 561 DPRINTF(5, ("done.\n")); 562 } 563 spltty(); 564 ttyld_close(tp, flag); 565 ttyclose(tp); 566 spl0(); 567 return(0); 568} 569 570static int 571scread(struct cdev *dev, struct uio *uio, int flag) 572{ 573 if (!sc_saver_keyb_only) 574 sc_touch_scrn_saver(); 575 return ttyread(dev, uio, flag); 576} 577 578static int 579sckbdevent(keyboard_t *thiskbd, int event, void *arg) 580{ 581 sc_softc_t *sc; 582 struct tty *cur_tty; 583 int c; 584 size_t len; 585 u_char *cp; 586 587 sc = (sc_softc_t *)arg; 588 /* assert(thiskbd == sc->kbd) */ 589 590 switch (event) { 591 case KBDIO_KEYINPUT: 592 break; 593 case KBDIO_UNLOADING: 594 sc->kbd = NULL; 595 sc->keyboard = -1; 596 kbd_release(thiskbd, (void *)&sc->keyboard); 597 return 0; 598 default: 599 return EINVAL; 600 } 601 602 /* 603 * Loop while there is still input to get from the keyboard. 604 * I don't think this is nessesary, and it doesn't fix 605 * the Xaccel-2.1 keyboard hang, but it can't hurt. XXX 606 */ 607 while ((c = scgetc(sc, SCGETC_NONBLOCK)) != NOKEY) { 608 609 cur_tty = VIRTUAL_TTY(sc, sc->cur_scp->index); 610 if (!ISTTYOPEN(cur_tty)) { 611 cur_tty = sc_console_tty; 612 if (!ISTTYOPEN(cur_tty)) 613 continue; 614 } 615 616 if ((*sc->cur_scp->tsw->te_input)(sc->cur_scp, c, cur_tty)) 617 continue; 618 619 switch (KEYFLAGS(c)) { 620 case 0x0000: /* normal key */ 621 ttyld_rint(cur_tty, KEYCHAR(c)); 622 break; 623 case FKEY: /* function key, return string */ 624 cp = kbd_get_fkeystr(thiskbd, KEYCHAR(c), &len); 625 if (cp != NULL) { 626 while (len-- > 0) 627 ttyld_rint(cur_tty, *cp++); 628 } 629 break; 630 case MKEY: /* meta is active, prepend ESC */ 631 ttyld_rint(cur_tty, 0x1b); 632 ttyld_rint(cur_tty, KEYCHAR(c)); 633 break; 634 case BKEY: /* backtab fixed sequence (esc [ Z) */ 635 ttyld_rint(cur_tty, 0x1b); 636 ttyld_rint(cur_tty, '['); 637 ttyld_rint(cur_tty, 'Z'); 638 break; 639 } 640 } 641 642 sc->cur_scp->status |= MOUSE_HIDDEN; 643 644 return 0; 645} 646 647static int 648scparam(struct tty *tp, struct termios *t) 649{ 650 tp->t_ispeed = t->c_ispeed; 651 tp->t_ospeed = t->c_ospeed; 652 tp->t_cflag = t->c_cflag; 653 return 0; 654} 655 656static int 657scioctl(struct cdev *dev, u_long cmd, caddr_t data, int flag, struct thread *td) 658{ 659 int error; 660 int i; 661 struct tty *tp; 662 sc_softc_t *sc; 663 scr_stat *scp; 664 int s; 665 666 tp = dev->si_tty; 667 668 /* If there is a user_ioctl function call that first */ 669 if (sc_user_ioctl) { 670 error = (*sc_user_ioctl)(dev, cmd, data, flag, td); 671 if (error != ENOIOCTL) 672 return error; 673 } 674 675 error = sc_vid_ioctl(tp, cmd, data, flag, td); 676 if (error != ENOIOCTL) 677 return error; 678 679#ifndef SC_NO_HISTORY 680 error = sc_hist_ioctl(tp, cmd, data, flag, td); 681 if (error != ENOIOCTL) 682 return error; 683#endif 684 685#ifndef SC_NO_SYSMOUSE 686 error = sc_mouse_ioctl(tp, cmd, data, flag, td); 687 if (error != ENOIOCTL) 688 return error; 689#endif 690 691 scp = sc_get_stat(tp->t_dev); 692 /* assert(scp != NULL) */ 693 /* scp is sc_console, if SC_VTY(dev) == SC_CONSOLECTL. */ 694 sc = scp->sc; 695 696 if (scp->tsw) { 697 error = (*scp->tsw->te_ioctl)(scp, tp, cmd, data, flag, td); 698 if (error != ENOIOCTL) 699 return error; 700 } 701 702 switch (cmd) { /* process console hardware related ioctl's */ 703 704 case GIO_ATTR: /* get current attributes */ 705 /* this ioctl is not processed here, but in the terminal emulator */ 706 return ENOTTY; 707 708 case GIO_COLOR: /* is this a color console ? */ 709 *(int *)data = (sc->adp->va_flags & V_ADP_COLOR) ? 1 : 0; 710 return 0; 711 712 case CONS_BLANKTIME: /* set screen saver timeout (0 = no saver) */ 713 if (*(int *)data < 0 || *(int *)data > MAX_BLANKTIME) 714 return EINVAL; 715 s = spltty(); 716 scrn_blank_time = *(int *)data; 717 run_scrn_saver = (scrn_blank_time != 0); 718 splx(s); 719 return 0; 720 721 case CONS_CURSORTYPE: /* set cursor type (obsolete) */ 722 s = spltty(); 723 *(int *)data &= CONS_CURSOR_ATTRS; 724 sc_change_cursor_shape(scp, *(int *)data, -1, -1); 725 splx(s); 726 return 0; 727 728 case CONS_GETCURSORSHAPE: /* get cursor shape (new interface) */ 729 if (((int *)data)[0] & CONS_LOCAL_CURSOR) { 730 ((int *)data)[0] = scp->curr_curs_attr.flags; 731 ((int *)data)[1] = scp->curr_curs_attr.base; 732 ((int *)data)[2] = scp->curr_curs_attr.height; 733 } else { 734 ((int *)data)[0] = sc->curs_attr.flags; 735 ((int *)data)[1] = sc->curs_attr.base; 736 ((int *)data)[2] = sc->curs_attr.height; 737 } 738 return 0; 739 740 case CONS_SETCURSORSHAPE: /* set cursor shape (new interface) */ 741 s = spltty(); 742 sc_change_cursor_shape(scp, ((int *)data)[0], 743 ((int *)data)[1], ((int *)data)[2]); 744 splx(s); 745 return 0; 746 747 case CONS_BELLTYPE: /* set bell type sound/visual */ 748 if ((*(int *)data) & 0x01) 749 sc->flags |= SC_VISUAL_BELL; 750 else 751 sc->flags &= ~SC_VISUAL_BELL; 752 if ((*(int *)data) & 0x02) 753 sc->flags |= SC_QUIET_BELL; 754 else 755 sc->flags &= ~SC_QUIET_BELL; 756 return 0; 757 758 case CONS_GETINFO: /* get current (virtual) console info */ 759 { 760 vid_info_t *ptr = (vid_info_t*)data; 761 if (ptr->size == sizeof(struct vid_info)) { 762 ptr->m_num = sc->cur_scp->index; 763 ptr->font_size = scp->font_size; 764 ptr->mv_col = scp->xpos; 765 ptr->mv_row = scp->ypos; 766 ptr->mv_csz = scp->xsize; 767 ptr->mv_rsz = scp->ysize; 768 ptr->mv_hsz = (scp->history != NULL) ? scp->history->vtb_rows : 0; 769 /* 770 * The following fields are filled by the terminal emulator. XXX 771 * 772 * ptr->mv_norm.fore 773 * ptr->mv_norm.back 774 * ptr->mv_rev.fore 775 * ptr->mv_rev.back 776 */ 777 ptr->mv_grfc.fore = 0; /* not supported */ 778 ptr->mv_grfc.back = 0; /* not supported */ 779 ptr->mv_ovscan = scp->border; 780 if (scp == sc->cur_scp) 781 save_kbd_state(scp); 782 ptr->mk_keylock = scp->status & LOCK_MASK; 783 return 0; 784 } 785 return EINVAL; 786 } 787 788 case CONS_GETVERS: /* get version number */ 789 *(int*)data = 0x200; /* version 2.0 */ 790 return 0; 791 792 case CONS_IDLE: /* see if the screen has been idle */ 793 /* 794 * When the screen is in the GRAPHICS_MODE or UNKNOWN_MODE, 795 * the user process may have been writing something on the 796 * screen and syscons is not aware of it. Declare the screen 797 * is NOT idle if it is in one of these modes. But there is 798 * an exception to it; if a screen saver is running in the 799 * graphics mode in the current screen, we should say that the 800 * screen has been idle. 801 */ 802 *(int *)data = (sc->flags & SC_SCRN_IDLE) 803 && (!ISGRAPHSC(sc->cur_scp) 804 || (sc->cur_scp->status & SAVER_RUNNING)); 805 return 0; 806 807 case CONS_SAVERMODE: /* set saver mode */ 808 switch(*(int *)data) { 809 case CONS_NO_SAVER: 810 case CONS_USR_SAVER: 811 /* if a LKM screen saver is running, stop it first. */ 812 scsplash_stick(FALSE); 813 saver_mode = *(int *)data; 814 s = spltty(); 815#ifdef DEV_SPLASH 816 if ((error = wait_scrn_saver_stop(NULL))) { 817 splx(s); 818 return error; 819 } 820#endif 821 run_scrn_saver = TRUE; 822 if (saver_mode == CONS_USR_SAVER) 823 scp->status |= SAVER_RUNNING; 824 else 825 scp->status &= ~SAVER_RUNNING; 826 scsplash_stick(TRUE); 827 splx(s); 828 break; 829 case CONS_LKM_SAVER: 830 s = spltty(); 831 if ((saver_mode == CONS_USR_SAVER) && (scp->status & SAVER_RUNNING)) 832 scp->status &= ~SAVER_RUNNING; 833 saver_mode = *(int *)data; 834 splx(s); 835 break; 836 default: 837 return EINVAL; 838 } 839 return 0; 840 841 case CONS_SAVERSTART: /* immediately start/stop the screen saver */ 842 /* 843 * Note that this ioctl does not guarantee the screen saver 844 * actually starts or stops. It merely attempts to do so... 845 */ 846 s = spltty(); 847 run_scrn_saver = (*(int *)data != 0); 848 if (run_scrn_saver) 849 sc->scrn_time_stamp -= scrn_blank_time; 850 splx(s); 851 return 0; 852 853 case CONS_SCRSHOT: /* get a screen shot */ 854 { 855 int retval, hist_rsz; 856 size_t lsize, csize; 857 vm_offset_t frbp, hstp; 858 unsigned lnum; 859 scrshot_t *ptr = (scrshot_t *)data; 860 void *outp = ptr->buf; 861 862 s = spltty(); 863 if (ISGRAPHSC(scp)) { 864 splx(s); 865 return EOPNOTSUPP; 866 } 867 hist_rsz = (scp->history != NULL) ? scp->history->vtb_rows : 0; 868 if ((ptr->x + ptr->xsize) > scp->xsize || 869 (ptr->y + ptr->ysize) > (scp->ysize + hist_rsz)) { 870 splx(s); 871 return EINVAL; 872 } 873 874 lsize = scp->xsize * sizeof(u_int16_t); 875 csize = ptr->xsize * sizeof(u_int16_t); 876 /* Pointer to the last line of framebuffer */ 877 frbp = scp->vtb.vtb_buffer + scp->ysize * lsize + ptr->x * 878 sizeof(u_int16_t); 879 /* Pointer to the last line of target buffer */ 880 (vm_offset_t)outp += ptr->ysize * csize; 881 /* Pointer to the last line of history buffer */ 882 if (scp->history != NULL) 883 hstp = scp->history->vtb_buffer + sc_vtb_tail(scp->history) * 884 sizeof(u_int16_t) + ptr->x * sizeof(u_int16_t); 885 else 886 hstp = 0; 887 888 retval = 0; 889 for (lnum = 0; lnum < (ptr->y + ptr->ysize); lnum++) { 890 if (lnum < scp->ysize) { 891 frbp -= lsize; 892 } else { 893 hstp -= lsize; 894 if (hstp < scp->history->vtb_buffer) 895 hstp += scp->history->vtb_rows * lsize; 896 frbp = hstp; 897 } 898 if (lnum < ptr->y) 899 continue; 900 (vm_offset_t)outp -= csize; 901 retval = copyout((void *)frbp, outp, csize); 902 if (retval != 0) 903 break; 904 } 905 splx(s); 906 return retval; 907 } 908 909 case VT_SETMODE: /* set screen switcher mode */ 910 { 911 struct vt_mode *mode; 912 struct proc *p1; 913 914 mode = (struct vt_mode *)data; 915 DPRINTF(5, ("sc%d: VT_SETMODE ", sc->unit)); 916 if (scp->smode.mode == VT_PROCESS) { 917 p1 = pfind(scp->pid); 918 if (scp->proc == p1 && scp->proc != td->td_proc) { 919 if (p1) 920 PROC_UNLOCK(p1); 921 DPRINTF(5, ("error EPERM\n")); 922 return EPERM; 923 } 924 if (p1) 925 PROC_UNLOCK(p1); 926 } 927 s = spltty(); 928 if (mode->mode == VT_AUTO) { 929 scp->smode.mode = VT_AUTO; 930 scp->proc = NULL; 931 scp->pid = 0; 932 DPRINTF(5, ("VT_AUTO, ")); 933 if ((scp == sc->cur_scp) && (sc->unit == sc_console_unit)) 934 cnavailable(sc_consptr, TRUE); 935 /* were we in the middle of the vty switching process? */ 936 if (finish_vt_rel(scp, TRUE, &s) == 0) 937 DPRINTF(5, ("reset WAIT_REL, ")); 938 if (finish_vt_acq(scp) == 0) 939 DPRINTF(5, ("reset WAIT_ACQ, ")); 940 } else { 941 if (!ISSIGVALID(mode->relsig) || !ISSIGVALID(mode->acqsig) 942 || !ISSIGVALID(mode->frsig)) { 943 splx(s); 944 DPRINTF(5, ("error EINVAL\n")); 945 return EINVAL; 946 } 947 DPRINTF(5, ("VT_PROCESS %d, ", td->td_proc->p_pid)); 948 bcopy(data, &scp->smode, sizeof(struct vt_mode)); 949 scp->proc = td->td_proc; 950 scp->pid = scp->proc->p_pid; 951 if ((scp == sc->cur_scp) && (sc->unit == sc_console_unit)) 952 cnavailable(sc_consptr, FALSE); 953 } 954 splx(s); 955 DPRINTF(5, ("\n")); 956 return 0; 957 } 958 959 case VT_GETMODE: /* get screen switcher mode */ 960 bcopy(&scp->smode, data, sizeof(struct vt_mode)); 961 return 0; 962 963 case VT_RELDISP: /* screen switcher ioctl */ 964 s = spltty(); 965 /* 966 * This must be the current vty which is in the VT_PROCESS 967 * switching mode... 968 */ 969 if ((scp != sc->cur_scp) || (scp->smode.mode != VT_PROCESS)) { 970 splx(s); 971 return EINVAL; 972 } 973 /* ...and this process is controlling it. */ 974 if (scp->proc != td->td_proc) { 975 splx(s); 976 return EPERM; 977 } 978 error = EINVAL; 979 switch(*(intptr_t *)data) { 980 case VT_FALSE: /* user refuses to release screen, abort */ 981 if ((error = finish_vt_rel(scp, FALSE, &s)) == 0) 982 DPRINTF(5, ("sc%d: VT_FALSE\n", sc->unit)); 983 break; 984 case VT_TRUE: /* user has released screen, go on */ 985 if ((error = finish_vt_rel(scp, TRUE, &s)) == 0) 986 DPRINTF(5, ("sc%d: VT_TRUE\n", sc->unit)); 987 break; 988 case VT_ACKACQ: /* acquire acknowledged, switch completed */ 989 if ((error = finish_vt_acq(scp)) == 0) 990 DPRINTF(5, ("sc%d: VT_ACKACQ\n", sc->unit)); 991 break; 992 default: 993 break; 994 } 995 splx(s); 996 return error; 997 998 case VT_OPENQRY: /* return free virtual console */ 999 for (i = sc->first_vty; i < sc->first_vty + sc->vtys; i++) { 1000 tp = VIRTUAL_TTY(sc, i); 1001 if (!ISTTYOPEN(tp)) { 1002 *(int *)data = i + 1; 1003 return 0; 1004 } 1005 } 1006 return EINVAL; 1007 1008 case VT_ACTIVATE: /* switch to screen *data */ 1009 i = (*(intptr_t *)data == 0) ? scp->index : (*(intptr_t *)data - 1); 1010 s = spltty(); 1011 sc_clean_up(sc->cur_scp); 1012 splx(s); 1013 return sc_switch_scr(sc, i); 1014 1015 case VT_WAITACTIVE: /* wait for switch to occur */ 1016 i = (*(intptr_t *)data == 0) ? scp->index : (*(intptr_t *)data - 1); 1017 if ((i < sc->first_vty) || (i >= sc->first_vty + sc->vtys)) 1018 return EINVAL; 1019 s = spltty(); 1020 error = sc_clean_up(sc->cur_scp); 1021 splx(s); 1022 if (error) 1023 return error; 1024 scp = sc_get_stat(SC_DEV(sc, i)); 1025 if (scp == scp->sc->cur_scp) 1026 return 0; 1027 while ((error=tsleep(&scp->smode, PZERO|PCATCH, 1028 "waitvt", 0)) == ERESTART) ; 1029 return error; 1030 1031 case VT_GETACTIVE: /* get active vty # */ 1032 *(int *)data = sc->cur_scp->index + 1; 1033 return 0; 1034 1035 case VT_GETINDEX: /* get this vty # */ 1036 *(int *)data = scp->index + 1; 1037 return 0; 1038 1039 case VT_LOCKSWITCH: /* prevent vty switching */ 1040 if ((*(int *)data) & 0x01) 1041 sc->flags |= SC_SCRN_VTYLOCK; 1042 else 1043 sc->flags &= ~SC_SCRN_VTYLOCK; 1044 return 0; 1045 1046 case KDENABIO: /* allow io operations */ 1047 error = suser(td); 1048 if (error != 0) 1049 return error; 1050 error = securelevel_gt(td->td_ucred, 0); 1051 if (error != 0) 1052 return error; 1053#ifdef __i386__ 1054 td->td_frame->tf_eflags |= PSL_IOPL; 1055#endif 1056 return 0; 1057 1058 case KDDISABIO: /* disallow io operations (default) */ 1059#ifdef __i386__ 1060 td->td_frame->tf_eflags &= ~PSL_IOPL; 1061#endif 1062 return 0; 1063 1064 case KDSKBSTATE: /* set keyboard state (locks) */ 1065 if (*(int *)data & ~LOCK_MASK) 1066 return EINVAL; 1067 scp->status &= ~LOCK_MASK; 1068 scp->status |= *(int *)data; 1069 if (scp == sc->cur_scp) 1070 update_kbd_state(scp, scp->status, LOCK_MASK); 1071 return 0; 1072 1073 case KDGKBSTATE: /* get keyboard state (locks) */ 1074 if (scp == sc->cur_scp) 1075 save_kbd_state(scp); 1076 *(int *)data = scp->status & LOCK_MASK; 1077 return 0; 1078 1079 case KDGETREPEAT: /* get keyboard repeat & delay rates */ 1080 case KDSETREPEAT: /* set keyboard repeat & delay rates (new) */ 1081 error = kbd_ioctl(sc->kbd, cmd, data); 1082 if (error == ENOIOCTL) 1083 error = ENODEV; 1084 return error; 1085 1086 case KDSETRAD: /* set keyboard repeat & delay rates (old) */ 1087 if (*(int *)data & ~0x7f) 1088 return EINVAL; 1089 error = kbd_ioctl(sc->kbd, cmd, data); 1090 if (error == ENOIOCTL) 1091 error = ENODEV; 1092 return error; 1093 1094 case KDSKBMODE: /* set keyboard mode */ 1095 switch (*(int *)data) { 1096 case K_XLATE: /* switch to XLT ascii mode */ 1097 case K_RAW: /* switch to RAW scancode mode */ 1098 case K_CODE: /* switch to CODE mode */ 1099 scp->kbd_mode = *(int *)data; 1100 if (scp == sc->cur_scp) 1101 kbd_ioctl(sc->kbd, cmd, data); 1102 return 0; 1103 default: 1104 return EINVAL; 1105 } 1106 /* NOT REACHED */ 1107 1108 case KDGKBMODE: /* get keyboard mode */ 1109 *(int *)data = scp->kbd_mode; 1110 return 0; 1111 1112 case KDGKBINFO: 1113 error = kbd_ioctl(sc->kbd, cmd, data); 1114 if (error == ENOIOCTL) 1115 error = ENODEV; 1116 return error; 1117 1118 case KDMKTONE: /* sound the bell */ 1119 if (*(int*)data) 1120 sc_bell(scp, (*(int*)data)&0xffff, 1121 (((*(int*)data)>>16)&0xffff)*hz/1000); 1122 else 1123 sc_bell(scp, scp->bell_pitch, scp->bell_duration); 1124 return 0; 1125 1126 case KIOCSOUND: /* make tone (*data) hz */ 1127 if (scp == sc->cur_scp) { 1128 if (*(int *)data) 1129 return sc_tone(*(int *)data); 1130 else 1131 return sc_tone(0); 1132 } 1133 return 0; 1134 1135 case KDGKBTYPE: /* get keyboard type */ 1136 error = kbd_ioctl(sc->kbd, cmd, data); 1137 if (error == ENOIOCTL) { 1138 /* always return something? XXX */ 1139 *(int *)data = 0; 1140 } 1141 return 0; 1142 1143 case KDSETLED: /* set keyboard LED status */ 1144 if (*(int *)data & ~LED_MASK) /* FIXME: LOCK_MASK? */ 1145 return EINVAL; 1146 scp->status &= ~LED_MASK; 1147 scp->status |= *(int *)data; 1148 if (scp == sc->cur_scp) 1149 update_kbd_leds(scp, scp->status); 1150 return 0; 1151 1152 case KDGETLED: /* get keyboard LED status */ 1153 if (scp == sc->cur_scp) 1154 save_kbd_state(scp); 1155 *(int *)data = scp->status & LED_MASK; 1156 return 0; 1157 1158 case CONS_SETKBD: /* set the new keyboard */ 1159 { 1160 keyboard_t *newkbd; 1161 1162 s = spltty(); 1163 newkbd = kbd_get_keyboard(*(int *)data); 1164 if (newkbd == NULL) { 1165 splx(s); 1166 return EINVAL; 1167 } 1168 error = 0; 1169 if (sc->kbd != newkbd) { 1170 i = kbd_allocate(newkbd->kb_name, newkbd->kb_unit, 1171 (void *)&sc->keyboard, sckbdevent, sc); 1172 /* i == newkbd->kb_index */ 1173 if (i >= 0) { 1174 if (sc->kbd != NULL) { 1175 save_kbd_state(sc->cur_scp); 1176 kbd_release(sc->kbd, (void *)&sc->keyboard); 1177 } 1178 sc->kbd = kbd_get_keyboard(i); /* sc->kbd == newkbd */ 1179 sc->keyboard = i; 1180 kbd_ioctl(sc->kbd, KDSKBMODE, 1181 (caddr_t)&sc->cur_scp->kbd_mode); 1182 update_kbd_state(sc->cur_scp, sc->cur_scp->status, 1183 LOCK_MASK); 1184 } else { 1185 error = EPERM; /* XXX */ 1186 } 1187 } 1188 splx(s); 1189 return error; 1190 } 1191 1192 case CONS_RELKBD: /* release the current keyboard */ 1193 s = spltty(); 1194 error = 0; 1195 if (sc->kbd != NULL) { 1196 save_kbd_state(sc->cur_scp); 1197 error = kbd_release(sc->kbd, (void *)&sc->keyboard); 1198 if (error == 0) { 1199 sc->kbd = NULL; 1200 sc->keyboard = -1; 1201 } 1202 } 1203 splx(s); 1204 return error; 1205 1206 case CONS_GETTERM: /* get the current terminal emulator info */ 1207 { 1208 sc_term_sw_t *sw; 1209 1210 if (((term_info_t *)data)->ti_index == 0) { 1211 sw = scp->tsw; 1212 } else { 1213 sw = sc_term_match_by_number(((term_info_t *)data)->ti_index); 1214 } 1215 if (sw != NULL) { 1216 strncpy(((term_info_t *)data)->ti_name, sw->te_name, 1217 sizeof(((term_info_t *)data)->ti_name)); 1218 strncpy(((term_info_t *)data)->ti_desc, sw->te_desc, 1219 sizeof(((term_info_t *)data)->ti_desc)); 1220 ((term_info_t *)data)->ti_flags = 0; 1221 return 0; 1222 } else { 1223 ((term_info_t *)data)->ti_name[0] = '\0'; 1224 ((term_info_t *)data)->ti_desc[0] = '\0'; 1225 ((term_info_t *)data)->ti_flags = 0; 1226 return EINVAL; 1227 } 1228 } 1229 1230 case CONS_SETTERM: /* set the current terminal emulator */ 1231 s = spltty(); 1232 error = sc_init_emulator(scp, ((term_info_t *)data)->ti_name); 1233 /* FIXME: what if scp == sc_console! XXX */ 1234 splx(s); 1235 return error; 1236 1237 case GIO_SCRNMAP: /* get output translation table */ 1238 bcopy(&sc->scr_map, data, sizeof(sc->scr_map)); 1239 return 0; 1240 1241 case PIO_SCRNMAP: /* set output translation table */ 1242 bcopy(data, &sc->scr_map, sizeof(sc->scr_map)); 1243 for (i=0; i<sizeof(sc->scr_map); i++) { 1244 sc->scr_rmap[sc->scr_map[i]] = i; 1245 } 1246 return 0; 1247 1248 case GIO_KEYMAP: /* get keyboard translation table */ 1249 case PIO_KEYMAP: /* set keyboard translation table */ 1250 case GIO_DEADKEYMAP: /* get accent key translation table */ 1251 case PIO_DEADKEYMAP: /* set accent key translation table */ 1252 case GETFKEY: /* get function key string */ 1253 case SETFKEY: /* set function key string */ 1254 error = kbd_ioctl(sc->kbd, cmd, data); 1255 if (error == ENOIOCTL) 1256 error = ENODEV; 1257 return error; 1258 1259#ifndef SC_NO_FONT_LOADING 1260 1261 case PIO_FONT8x8: /* set 8x8 dot font */ 1262 if (!ISFONTAVAIL(sc->adp->va_flags)) 1263 return ENXIO; 1264 bcopy(data, sc->font_8, 8*256); 1265 sc->fonts_loaded |= FONT_8; 1266 /* 1267 * FONT KLUDGE 1268 * Always use the font page #0. XXX 1269 * Don't load if the current font size is not 8x8. 1270 */ 1271 if (ISTEXTSC(sc->cur_scp) && (sc->cur_scp->font_size < 14)) 1272 sc_load_font(sc->cur_scp, 0, 8, sc->font_8, 0, 256); 1273 return 0; 1274 1275 case GIO_FONT8x8: /* get 8x8 dot font */ 1276 if (!ISFONTAVAIL(sc->adp->va_flags)) 1277 return ENXIO; 1278 if (sc->fonts_loaded & FONT_8) { 1279 bcopy(sc->font_8, data, 8*256); 1280 return 0; 1281 } 1282 else 1283 return ENXIO; 1284 1285 case PIO_FONT8x14: /* set 8x14 dot font */ 1286 if (!ISFONTAVAIL(sc->adp->va_flags)) 1287 return ENXIO; 1288 bcopy(data, sc->font_14, 14*256); 1289 sc->fonts_loaded |= FONT_14; 1290 /* 1291 * FONT KLUDGE 1292 * Always use the font page #0. XXX 1293 * Don't load if the current font size is not 8x14. 1294 */ 1295 if (ISTEXTSC(sc->cur_scp) 1296 && (sc->cur_scp->font_size >= 14) 1297 && (sc->cur_scp->font_size < 16)) 1298 sc_load_font(sc->cur_scp, 0, 14, sc->font_14, 0, 256); 1299 return 0; 1300 1301 case GIO_FONT8x14: /* get 8x14 dot font */ 1302 if (!ISFONTAVAIL(sc->adp->va_flags)) 1303 return ENXIO; 1304 if (sc->fonts_loaded & FONT_14) { 1305 bcopy(sc->font_14, data, 14*256); 1306 return 0; 1307 } 1308 else 1309 return ENXIO; 1310 1311 case PIO_FONT8x16: /* set 8x16 dot font */ 1312 if (!ISFONTAVAIL(sc->adp->va_flags)) 1313 return ENXIO; 1314 bcopy(data, sc->font_16, 16*256); 1315 sc->fonts_loaded |= FONT_16; 1316 /* 1317 * FONT KLUDGE 1318 * Always use the font page #0. XXX 1319 * Don't load if the current font size is not 8x16. 1320 */ 1321 if (ISTEXTSC(sc->cur_scp) && (sc->cur_scp->font_size >= 16)) 1322 sc_load_font(sc->cur_scp, 0, 16, sc->font_16, 0, 256); 1323 return 0; 1324 1325 case GIO_FONT8x16: /* get 8x16 dot font */ 1326 if (!ISFONTAVAIL(sc->adp->va_flags)) 1327 return ENXIO; 1328 if (sc->fonts_loaded & FONT_16) { 1329 bcopy(sc->font_16, data, 16*256); 1330 return 0; 1331 } 1332 else 1333 return ENXIO; 1334 1335#endif /* SC_NO_FONT_LOADING */ 1336 1337#ifdef PC98 1338 case ADJUST_CLOCK: /* /dev/rtc for 98note resume */ 1339 inittodr(0); 1340 return 0; 1341#endif 1342 1343 default: 1344 break; 1345 } 1346 1347 return (ttyioctl(dev, cmd, data, flag, td)); 1348} 1349 1350static void 1351scstart(struct tty *tp) 1352{ 1353 struct clist *rbp; 1354 int s, len; 1355 u_char buf[PCBURST]; 1356 scr_stat *scp = sc_get_stat(tp->t_dev); 1357 1358 if (scp->status & SLKED || 1359 (scp == scp->sc->cur_scp && scp->sc->blink_in_progress)) 1360 return; 1361 s = spltty(); 1362 if (!(tp->t_state & (TS_TIMEOUT | TS_BUSY | TS_TTSTOP))) { 1363 tp->t_state |= TS_BUSY; 1364 rbp = &tp->t_outq; 1365 while (rbp->c_cc) { 1366 len = q_to_b(rbp, buf, PCBURST); 1367 splx(s); 1368 sc_puts(scp, buf, len); 1369 s = spltty(); 1370 } 1371 tp->t_state &= ~TS_BUSY; 1372 ttwwakeup(tp); 1373 } 1374 splx(s); 1375} 1376 1377static void 1378sccnprobe(struct consdev *cp) 1379{ 1380#if !__alpha__ 1381 int unit; 1382 int flags; 1383 1384 cp->cn_pri = sc_get_cons_priority(&unit, &flags); 1385 1386 /* a video card is always required */ 1387 if (!scvidprobe(unit, flags, TRUE)) 1388 cp->cn_pri = CN_DEAD; 1389 1390 /* syscons will become console even when there is no keyboard */ 1391 sckbdprobe(unit, flags, TRUE); 1392 1393 if (cp->cn_pri == CN_DEAD) 1394 return; 1395 1396 /* initialize required fields */ 1397 sprintf(cp->cn_name, "consolectl"); 1398#endif /* !__alpha__ */ 1399 1400#if __alpha__ 1401 /* 1402 * alpha use sccnattach() rather than cnprobe()/cninit()/cnterm() 1403 * interface to install the console. Always return CN_DEAD from 1404 * here. 1405 */ 1406 cp->cn_pri = CN_DEAD; 1407#endif /* __alpha__ */ 1408} 1409 1410static void 1411sccninit(struct consdev *cp) 1412{ 1413#if !__alpha__ 1414 int unit; 1415 int flags; 1416 1417 sc_get_cons_priority(&unit, &flags); 1418 scinit(unit, flags | SC_KERNEL_CONSOLE); 1419 sc_console_unit = unit; 1420 sc_console = sc_get_stat(sc_get_softc(unit, SC_KERNEL_CONSOLE)->dev[0]); 1421 sc_consptr = cp; 1422#endif /* !__alpha__ */ 1423 1424#if __alpha__ 1425 /* SHOULDN'T REACH HERE */ 1426#endif /* __alpha__ */ 1427} 1428 1429static void 1430sccnterm(struct consdev *cp) 1431{ 1432 /* we are not the kernel console any more, release everything */ 1433 1434 if (sc_console_unit < 0) 1435 return; /* shouldn't happen */ 1436 1437#if !__alpha__ 1438#if 0 /* XXX */ 1439 sc_clear_screen(sc_console); 1440 sccnupdate(sc_console); 1441#endif 1442 scterm(sc_console_unit, SC_KERNEL_CONSOLE); 1443 sc_console_unit = -1; 1444 sc_console = NULL; 1445#endif /* !__alpha__ */ 1446 1447#if __alpha__ 1448 /* do nothing XXX */ 1449#endif /* __alpha__ */ 1450} 1451 1452#ifdef __alpha__ 1453 1454void 1455sccnattach(void) 1456{ 1457 static struct consdev consdev; 1458 int unit; 1459 int flags; 1460 1461 bcopy(&sc_consdev, &consdev, sizeof(sc_consdev)); 1462 consdev.cn_pri = sc_get_cons_priority(&unit, &flags); 1463 1464 /* a video card is always required */ 1465 if (!scvidprobe(unit, flags, TRUE)) 1466 consdev.cn_pri = CN_DEAD; 1467 1468 /* alpha doesn't allow the console being without a keyboard... Why? */ 1469 if (!sckbdprobe(unit, flags, TRUE)) 1470 consdev.cn_pri = CN_DEAD; 1471 1472 if (consdev.cn_pri == CN_DEAD) 1473 return; 1474 1475 scinit(unit, flags | SC_KERNEL_CONSOLE); 1476 sc_console_unit = unit; 1477 sc_consptr = &consdev; 1478 sc_console = sc_get_stat(sc_get_softc(unit, SC_KERNEL_CONSOLE)->dev[0]); 1479 sprintf(consdev.cn_name, "ttyv%r", 0); 1480 cnadd(&consdev); 1481} 1482 1483#endif /* __alpha__ */ 1484 1485static void 1486sccnputc(struct consdev *cd, int c) 1487{ 1488 u_char buf[1]; 1489 scr_stat *scp = sc_console; 1490 void *save; 1491#ifndef SC_NO_HISTORY 1492 struct tty *tp; 1493#endif /* !SC_NO_HISTORY */ 1494 int s; 1495 1496 /* assert(sc_console != NULL) */ 1497 1498#ifndef SC_NO_HISTORY 1499 if (scp == scp->sc->cur_scp && scp->status & SLKED) { 1500 scp->status &= ~SLKED; 1501 update_kbd_state(scp, scp->status, SLKED); 1502 if (scp->status & BUFFER_SAVED) { 1503 if (!sc_hist_restore(scp)) 1504 sc_remove_cutmarking(scp); 1505 scp->status &= ~BUFFER_SAVED; 1506 scp->status |= CURSOR_ENABLED; 1507 sc_draw_cursor_image(scp); 1508 } 1509 tp = VIRTUAL_TTY(scp->sc, scp->index); 1510 if (ISTTYOPEN(tp)) 1511 scstart(tp); 1512 } 1513#endif /* !SC_NO_HISTORY */ 1514 1515 save = scp->ts; 1516 if (kernel_console_ts != NULL) 1517 scp->ts = kernel_console_ts; 1518 buf[0] = c; 1519 sc_puts(scp, buf, 1); 1520 scp->ts = save; 1521 1522 s = spltty(); /* block sckbdevent and scrn_timer */ 1523 sccnupdate(scp); 1524 splx(s); 1525} 1526 1527static int 1528sccngetc(struct consdev *cd) 1529{ 1530 return sccngetch(0); 1531} 1532 1533static int 1534sccncheckc(struct consdev *cd) 1535{ 1536 return sccngetch(SCGETC_NONBLOCK); 1537} 1538 1539static void 1540sccndbctl(struct consdev *cd, int on) 1541{ 1542 /* assert(sc_console_unit >= 0) */ 1543 /* try to switch to the kernel console screen */ 1544 if (on && debugger == 0) { 1545 /* 1546 * TRY to make sure the screen saver is stopped, 1547 * and the screen is updated before switching to 1548 * the vty0. 1549 */ 1550 scrn_timer(NULL); 1551 if (!cold 1552 && sc_console->sc->cur_scp->smode.mode == VT_AUTO 1553 && sc_console->smode.mode == VT_AUTO) { 1554 sc_console->sc->cur_scp->status |= MOUSE_HIDDEN; 1555 ++debugger; /* XXX */ 1556#ifdef DDB 1557 /* unlock vty switching */ 1558 sc_console->sc->flags &= ~SC_SCRN_VTYLOCK; 1559#endif 1560 sc_switch_scr(sc_console->sc, sc_console->index); 1561 --debugger; /* XXX */ 1562 } 1563 } 1564 if (on) 1565 ++debugger; 1566 else 1567 --debugger; 1568} 1569 1570static int 1571sccngetch(int flags) 1572{ 1573 static struct fkeytab fkey; 1574 static int fkeycp; 1575 scr_stat *scp; 1576 u_char *p; 1577 int cur_mode; 1578 int s = spltty(); /* block sckbdevent and scrn_timer while we poll */ 1579 int c; 1580 1581 /* assert(sc_console != NULL) */ 1582 1583 /* 1584 * Stop the screen saver and update the screen if necessary. 1585 * What if we have been running in the screen saver code... XXX 1586 */ 1587 sc_touch_scrn_saver(); 1588 scp = sc_console->sc->cur_scp; /* XXX */ 1589 sccnupdate(scp); 1590 1591 if (fkeycp < fkey.len) { 1592 splx(s); 1593 return fkey.str[fkeycp++]; 1594 } 1595 1596 if (scp->sc->kbd == NULL) { 1597 splx(s); 1598 return -1; 1599 } 1600 1601 /* 1602 * Make sure the keyboard is accessible even when the kbd device 1603 * driver is disabled. 1604 */ 1605 kbd_enable(scp->sc->kbd); 1606 1607 /* we shall always use the keyboard in the XLATE mode here */ 1608 cur_mode = scp->kbd_mode; 1609 scp->kbd_mode = K_XLATE; 1610 kbd_ioctl(scp->sc->kbd, KDSKBMODE, (caddr_t)&scp->kbd_mode); 1611 1612 kbd_poll(scp->sc->kbd, TRUE); 1613 c = scgetc(scp->sc, SCGETC_CN | flags); 1614 kbd_poll(scp->sc->kbd, FALSE); 1615 1616 scp->kbd_mode = cur_mode; 1617 kbd_ioctl(scp->sc->kbd, KDSKBMODE, (caddr_t)&scp->kbd_mode); 1618 kbd_disable(scp->sc->kbd); 1619 splx(s); 1620 1621 switch (KEYFLAGS(c)) { 1622 case 0: /* normal char */ 1623 return KEYCHAR(c); 1624 case FKEY: /* function key */ 1625 p = kbd_get_fkeystr(scp->sc->kbd, KEYCHAR(c), (size_t *)&fkeycp); 1626 fkey.len = fkeycp; 1627 if ((p != NULL) && (fkey.len > 0)) { 1628 bcopy(p, fkey.str, fkey.len); 1629 fkeycp = 1; 1630 return fkey.str[0]; 1631 } 1632 return c; /* XXX */ 1633 case NOKEY: 1634 case ERRKEY: 1635 default: 1636 return -1; 1637 } 1638 /* NOT REACHED */ 1639} 1640 1641static void 1642sccnupdate(scr_stat *scp) 1643{ 1644 /* this is a cut-down version of scrn_timer()... */ 1645 1646 if (scp->sc->font_loading_in_progress || scp->sc->videoio_in_progress) 1647 return; 1648 1649 if (debugger > 0 || panicstr || shutdown_in_progress) { 1650 sc_touch_scrn_saver(); 1651 } else if (scp != scp->sc->cur_scp) { 1652 return; 1653 } 1654 1655 if (!run_scrn_saver) 1656 scp->sc->flags &= ~SC_SCRN_IDLE; 1657#ifdef DEV_SPLASH 1658 if ((saver_mode != CONS_LKM_SAVER) || !(scp->sc->flags & SC_SCRN_IDLE)) 1659 if (scp->sc->flags & SC_SCRN_BLANKED) 1660 stop_scrn_saver(scp->sc, current_saver); 1661#endif 1662 1663 if (scp != scp->sc->cur_scp || scp->sc->blink_in_progress 1664 || scp->sc->switch_in_progress) 1665 return; 1666 /* 1667 * FIXME: unlike scrn_timer(), we call scrn_update() from here even 1668 * when write_in_progress is non-zero. XXX 1669 */ 1670 1671 if (!ISGRAPHSC(scp) && !(scp->sc->flags & SC_SCRN_BLANKED)) 1672 scrn_update(scp, TRUE); 1673} 1674 1675static void 1676scrn_timer(void *arg) 1677{ 1678#ifndef PC98 1679 static int kbd_interval = 0; 1680#endif 1681 struct timeval tv; 1682 sc_softc_t *sc; 1683 scr_stat *scp; 1684 int again; 1685 int s; 1686 1687 again = (arg != NULL); 1688 if (arg != NULL) 1689 sc = (sc_softc_t *)arg; 1690 else if (sc_console != NULL) 1691 sc = sc_console->sc; 1692 else 1693 return; 1694 1695 /* don't do anything when we are performing some I/O operations */ 1696 if (sc->font_loading_in_progress || sc->videoio_in_progress) { 1697 if (again) 1698 timeout(scrn_timer, sc, hz / 10); 1699 return; 1700 } 1701 s = spltty(); 1702 1703#ifndef PC98 1704 if ((sc->kbd == NULL) && (sc->config & SC_AUTODETECT_KBD)) { 1705 /* try to allocate a keyboard automatically */ 1706 if (++kbd_interval >= 25) { 1707 sc->keyboard = kbd_allocate("*", -1, (void *)&sc->keyboard, 1708 sckbdevent, sc); 1709 if (sc->keyboard >= 0) { 1710 sc->kbd = kbd_get_keyboard(sc->keyboard); 1711 kbd_ioctl(sc->kbd, KDSKBMODE, 1712 (caddr_t)&sc->cur_scp->kbd_mode); 1713 update_kbd_state(sc->cur_scp, sc->cur_scp->status, 1714 LOCK_MASK); 1715 } 1716 kbd_interval = 0; 1717 } 1718 } 1719#endif /* PC98 */ 1720 1721 /* find the vty to update */ 1722 scp = sc->cur_scp; 1723 1724 /* should we stop the screen saver? */ 1725 getmicrouptime(&tv); 1726 if (debugger > 0 || panicstr || shutdown_in_progress) 1727 sc_touch_scrn_saver(); 1728 if (run_scrn_saver) { 1729 if (tv.tv_sec > sc->scrn_time_stamp + scrn_blank_time) 1730 sc->flags |= SC_SCRN_IDLE; 1731 else 1732 sc->flags &= ~SC_SCRN_IDLE; 1733 } else { 1734 sc->scrn_time_stamp = tv.tv_sec; 1735 sc->flags &= ~SC_SCRN_IDLE; 1736 if (scrn_blank_time > 0) 1737 run_scrn_saver = TRUE; 1738 } 1739#ifdef DEV_SPLASH 1740 if ((saver_mode != CONS_LKM_SAVER) || !(sc->flags & SC_SCRN_IDLE)) 1741 if (sc->flags & SC_SCRN_BLANKED) 1742 stop_scrn_saver(sc, current_saver); 1743#endif 1744 1745 /* should we just return ? */ 1746 if (sc->blink_in_progress || sc->switch_in_progress 1747 || sc->write_in_progress) { 1748 if (again) 1749 timeout(scrn_timer, sc, hz / 10); 1750 splx(s); 1751 return; 1752 } 1753 1754 /* Update the screen */ 1755 scp = sc->cur_scp; /* cur_scp may have changed... */ 1756 if (!ISGRAPHSC(scp) && !(sc->flags & SC_SCRN_BLANKED)) 1757 scrn_update(scp, TRUE); 1758 1759#ifdef DEV_SPLASH 1760 /* should we activate the screen saver? */ 1761 if ((saver_mode == CONS_LKM_SAVER) && (sc->flags & SC_SCRN_IDLE)) 1762 if (!ISGRAPHSC(scp) || (sc->flags & SC_SCRN_BLANKED)) 1763 (*current_saver)(sc, TRUE); 1764#endif 1765 1766 if (again) 1767 timeout(scrn_timer, sc, hz / 25); 1768 splx(s); 1769} 1770 1771static int 1772and_region(int *s1, int *e1, int s2, int e2) 1773{ 1774 if (*e1 < s2 || e2 < *s1) 1775 return FALSE; 1776 *s1 = imax(*s1, s2); 1777 *e1 = imin(*e1, e2); 1778 return TRUE; 1779} 1780 1781static void 1782scrn_update(scr_stat *scp, int show_cursor) 1783{ 1784 int start; 1785 int end; 1786 int s; 1787 int e; 1788 1789 /* assert(scp == scp->sc->cur_scp) */ 1790 1791 ++scp->sc->videoio_in_progress; 1792 1793#ifndef SC_NO_CUTPASTE 1794 /* remove the previous mouse pointer image if necessary */ 1795 if (scp->status & MOUSE_VISIBLE) { 1796 s = scp->mouse_pos; 1797 e = scp->mouse_pos + scp->xsize + 1; 1798 if ((scp->status & (MOUSE_MOVED | MOUSE_HIDDEN)) 1799 || and_region(&s, &e, scp->start, scp->end) 1800 || ((scp->status & CURSOR_ENABLED) && 1801 (scp->cursor_pos != scp->cursor_oldpos) && 1802 (and_region(&s, &e, scp->cursor_pos, scp->cursor_pos) 1803 || and_region(&s, &e, scp->cursor_oldpos, scp->cursor_oldpos)))) { 1804 sc_remove_mouse_image(scp); 1805 if (scp->end >= scp->xsize*scp->ysize) 1806 scp->end = scp->xsize*scp->ysize - 1; 1807 } 1808 } 1809#endif /* !SC_NO_CUTPASTE */ 1810 1811#if 1 1812 /* debug: XXX */ 1813 if (scp->end >= scp->xsize*scp->ysize) { 1814 printf("scrn_update(): scp->end %d > size_of_screen!!\n", scp->end); 1815 scp->end = scp->xsize*scp->ysize - 1; 1816 } 1817 if (scp->start < 0) { 1818 printf("scrn_update(): scp->start %d < 0\n", scp->start); 1819 scp->start = 0; 1820 } 1821#endif 1822 1823 /* update screen image */ 1824 if (scp->start <= scp->end) { 1825 if (scp->mouse_cut_end >= 0) { 1826 /* there is a marked region for cut & paste */ 1827 if (scp->mouse_cut_start <= scp->mouse_cut_end) { 1828 start = scp->mouse_cut_start; 1829 end = scp->mouse_cut_end; 1830 } else { 1831 start = scp->mouse_cut_end; 1832 end = scp->mouse_cut_start - 1; 1833 } 1834 s = start; 1835 e = end; 1836 /* does the cut-mark region overlap with the update region? */ 1837 if (and_region(&s, &e, scp->start, scp->end)) { 1838 (*scp->rndr->draw)(scp, s, e - s + 1, TRUE); 1839 s = 0; 1840 e = start - 1; 1841 if (and_region(&s, &e, scp->start, scp->end)) 1842 (*scp->rndr->draw)(scp, s, e - s + 1, FALSE); 1843 s = end + 1; 1844 e = scp->xsize*scp->ysize - 1; 1845 if (and_region(&s, &e, scp->start, scp->end)) 1846 (*scp->rndr->draw)(scp, s, e - s + 1, FALSE); 1847 } else { 1848 (*scp->rndr->draw)(scp, scp->start, 1849 scp->end - scp->start + 1, FALSE); 1850 } 1851 } else { 1852 (*scp->rndr->draw)(scp, scp->start, 1853 scp->end - scp->start + 1, FALSE); 1854 } 1855 } 1856 1857 /* we are not to show the cursor and the mouse pointer... */ 1858 if (!show_cursor) { 1859 scp->end = 0; 1860 scp->start = scp->xsize*scp->ysize - 1; 1861 --scp->sc->videoio_in_progress; 1862 return; 1863 } 1864 1865 /* update cursor image */ 1866 if (scp->status & CURSOR_ENABLED) { 1867 s = scp->start; 1868 e = scp->end; 1869 /* did cursor move since last time ? */ 1870 if (scp->cursor_pos != scp->cursor_oldpos) { 1871 /* do we need to remove old cursor image ? */ 1872 if (!and_region(&s, &e, scp->cursor_oldpos, scp->cursor_oldpos)) 1873 sc_remove_cursor_image(scp); 1874 sc_draw_cursor_image(scp); 1875 } else { 1876 if (and_region(&s, &e, scp->cursor_pos, scp->cursor_pos)) 1877 /* cursor didn't move, but has been overwritten */ 1878 sc_draw_cursor_image(scp); 1879 else if (scp->curs_attr.flags & CONS_BLINK_CURSOR) 1880 /* if it's a blinking cursor, update it */ 1881 (*scp->rndr->blink_cursor)(scp, scp->cursor_pos, 1882 sc_inside_cutmark(scp, 1883 scp->cursor_pos)); 1884 } 1885 } 1886 1887#ifndef SC_NO_CUTPASTE 1888 /* update "pseudo" mouse pointer image */ 1889 if (scp->sc->flags & SC_MOUSE_ENABLED) { 1890 if (!(scp->status & (MOUSE_VISIBLE | MOUSE_HIDDEN))) { 1891 scp->status &= ~MOUSE_MOVED; 1892 sc_draw_mouse_image(scp); 1893 } 1894 } 1895#endif /* SC_NO_CUTPASTE */ 1896 1897 scp->end = 0; 1898 scp->start = scp->xsize*scp->ysize - 1; 1899 1900 --scp->sc->videoio_in_progress; 1901} 1902 1903#ifdef DEV_SPLASH 1904static int 1905scsplash_callback(int event, void *arg) 1906{ 1907 sc_softc_t *sc; 1908 int error; 1909 1910 sc = (sc_softc_t *)arg; 1911 1912 switch (event) { 1913 case SPLASH_INIT: 1914 if (add_scrn_saver(scsplash_saver) == 0) { 1915 sc->flags &= ~SC_SAVER_FAILED; 1916 run_scrn_saver = TRUE; 1917 if (cold && !(boothowto & (RB_VERBOSE | RB_CONFIG))) { 1918 scsplash_stick(TRUE); 1919 (*current_saver)(sc, TRUE); 1920 } 1921 } 1922 return 0; 1923 1924 case SPLASH_TERM: 1925 if (current_saver == scsplash_saver) { 1926 scsplash_stick(FALSE); 1927 error = remove_scrn_saver(scsplash_saver); 1928 if (error) 1929 return error; 1930 } 1931 return 0; 1932 1933 default: 1934 return EINVAL; 1935 } 1936} 1937 1938static void 1939scsplash_saver(sc_softc_t *sc, int show) 1940{ 1941 static int busy = FALSE; 1942 scr_stat *scp; 1943 1944 if (busy) 1945 return; 1946 busy = TRUE; 1947 1948 scp = sc->cur_scp; 1949 if (show) { 1950 if (!(sc->flags & SC_SAVER_FAILED)) { 1951 if (!(sc->flags & SC_SCRN_BLANKED)) 1952 set_scrn_saver_mode(scp, -1, NULL, 0); 1953 switch (splash(sc->adp, TRUE)) { 1954 case 0: /* succeeded */ 1955 break; 1956 case EAGAIN: /* try later */ 1957 restore_scrn_saver_mode(scp, FALSE); 1958 sc_touch_scrn_saver(); /* XXX */ 1959 break; 1960 default: 1961 sc->flags |= SC_SAVER_FAILED; 1962 scsplash_stick(FALSE); 1963 restore_scrn_saver_mode(scp, TRUE); 1964 printf("scsplash_saver(): failed to put up the image\n"); 1965 break; 1966 } 1967 } 1968 } else if (!sticky_splash) { 1969 if ((sc->flags & SC_SCRN_BLANKED) && (splash(sc->adp, FALSE) == 0)) 1970 restore_scrn_saver_mode(scp, TRUE); 1971 } 1972 busy = FALSE; 1973} 1974 1975static int 1976add_scrn_saver(void (*this_saver)(sc_softc_t *, int)) 1977{ 1978#if 0 1979 int error; 1980 1981 if (current_saver != none_saver) { 1982 error = remove_scrn_saver(current_saver); 1983 if (error) 1984 return error; 1985 } 1986#endif 1987 if (current_saver != none_saver) 1988 return EBUSY; 1989 1990 run_scrn_saver = FALSE; 1991 saver_mode = CONS_LKM_SAVER; 1992 current_saver = this_saver; 1993 return 0; 1994} 1995 1996static int 1997remove_scrn_saver(void (*this_saver)(sc_softc_t *, int)) 1998{ 1999 if (current_saver != this_saver) 2000 return EINVAL; 2001 2002#if 0 2003 /* 2004 * In order to prevent `current_saver' from being called by 2005 * the timeout routine `scrn_timer()' while we manipulate 2006 * the saver list, we shall set `current_saver' to `none_saver' 2007 * before stopping the current saver, rather than blocking by `splXX()'. 2008 */ 2009 current_saver = none_saver; 2010 if (scrn_blanked) 2011 stop_scrn_saver(this_saver); 2012#endif 2013 2014 /* unblank all blanked screens */ 2015 wait_scrn_saver_stop(NULL); 2016 if (scrn_blanked) 2017 return EBUSY; 2018 2019 current_saver = none_saver; 2020 return 0; 2021} 2022 2023static int 2024set_scrn_saver_mode(scr_stat *scp, int mode, u_char *pal, int border) 2025{ 2026 int s; 2027 2028 /* assert(scp == scp->sc->cur_scp) */ 2029 s = spltty(); 2030 if (!ISGRAPHSC(scp)) 2031 sc_remove_cursor_image(scp); 2032 scp->splash_save_mode = scp->mode; 2033 scp->splash_save_status = scp->status & (GRAPHICS_MODE | PIXEL_MODE); 2034 scp->status &= ~(GRAPHICS_MODE | PIXEL_MODE); 2035 scp->status |= (UNKNOWN_MODE | SAVER_RUNNING); 2036 scp->sc->flags |= SC_SCRN_BLANKED; 2037 ++scrn_blanked; 2038 splx(s); 2039 if (mode < 0) 2040 return 0; 2041 scp->mode = mode; 2042 if (set_mode(scp) == 0) { 2043 if (scp->sc->adp->va_info.vi_flags & V_INFO_GRAPHICS) 2044 scp->status |= GRAPHICS_MODE; 2045#ifndef SC_NO_PALETTE_LOADING 2046 if (pal != NULL) 2047 load_palette(scp->sc->adp, pal); 2048#endif 2049 sc_set_border(scp, border); 2050 return 0; 2051 } else { 2052 s = spltty(); 2053 scp->mode = scp->splash_save_mode; 2054 scp->status &= ~(UNKNOWN_MODE | SAVER_RUNNING); 2055 scp->status |= scp->splash_save_status; 2056 splx(s); 2057 return 1; 2058 } 2059} 2060 2061static int 2062restore_scrn_saver_mode(scr_stat *scp, int changemode) 2063{ 2064 int mode; 2065 int status; 2066 int s; 2067 2068 /* assert(scp == scp->sc->cur_scp) */ 2069 s = spltty(); 2070 mode = scp->mode; 2071 status = scp->status; 2072 scp->mode = scp->splash_save_mode; 2073 scp->status &= ~(UNKNOWN_MODE | SAVER_RUNNING); 2074 scp->status |= scp->splash_save_status; 2075 scp->sc->flags &= ~SC_SCRN_BLANKED; 2076 if (!changemode) { 2077 if (!ISGRAPHSC(scp)) 2078 sc_draw_cursor_image(scp); 2079 --scrn_blanked; 2080 splx(s); 2081 return 0; 2082 } 2083 if (set_mode(scp) == 0) { 2084#ifndef SC_NO_PALETTE_LOADING 2085 load_palette(scp->sc->adp, scp->sc->palette); 2086#endif 2087 --scrn_blanked; 2088 splx(s); 2089 return 0; 2090 } else { 2091 scp->mode = mode; 2092 scp->status = status; 2093 splx(s); 2094 return 1; 2095 } 2096} 2097 2098static void 2099stop_scrn_saver(sc_softc_t *sc, void (*saver)(sc_softc_t *, int)) 2100{ 2101 (*saver)(sc, FALSE); 2102 run_scrn_saver = FALSE; 2103 /* the screen saver may have chosen not to stop after all... */ 2104 if (sc->flags & SC_SCRN_BLANKED) 2105 return; 2106 2107 mark_all(sc->cur_scp); 2108 if (sc->delayed_next_scr) 2109 sc_switch_scr(sc, sc->delayed_next_scr - 1); 2110 if (debugger == 0) 2111 wakeup(&scrn_blanked); 2112} 2113 2114static int 2115wait_scrn_saver_stop(sc_softc_t *sc) 2116{ 2117 int error = 0; 2118 2119 while (scrn_blanked > 0) { 2120 run_scrn_saver = FALSE; 2121 if (sc && !(sc->flags & SC_SCRN_BLANKED)) { 2122 error = 0; 2123 break; 2124 } 2125 error = tsleep(&scrn_blanked, PZERO | PCATCH, "scrsav", 0); 2126 if ((error != 0) && (error != ERESTART)) 2127 break; 2128 } 2129 run_scrn_saver = FALSE; 2130 return error; 2131} 2132#endif /* DEV_SPLASH */ 2133 2134void 2135sc_touch_scrn_saver(void) 2136{ 2137 scsplash_stick(FALSE); 2138 run_scrn_saver = FALSE; 2139} 2140 2141int 2142sc_switch_scr(sc_softc_t *sc, u_int next_scr) 2143{ 2144 scr_stat *cur_scp; 2145 struct tty *tp; 2146 struct proc *p; 2147 int s; 2148 2149 DPRINTF(5, ("sc0: sc_switch_scr() %d ", next_scr + 1)); 2150 2151 if (sc->cur_scp == NULL) 2152 return (0); 2153 2154 /* prevent switch if previously requested */ 2155 if (sc->flags & SC_SCRN_VTYLOCK) { 2156 sc_bell(sc->cur_scp, sc->cur_scp->bell_pitch, 2157 sc->cur_scp->bell_duration); 2158 return EPERM; 2159 } 2160 2161 /* delay switch if the screen is blanked or being updated */ 2162 if ((sc->flags & SC_SCRN_BLANKED) || sc->write_in_progress 2163 || sc->blink_in_progress || sc->videoio_in_progress) { 2164 sc->delayed_next_scr = next_scr + 1; 2165 sc_touch_scrn_saver(); 2166 DPRINTF(5, ("switch delayed\n")); 2167 return 0; 2168 } 2169 2170 s = spltty(); 2171 cur_scp = sc->cur_scp; 2172 2173 /* we are in the middle of the vty switching process... */ 2174 if (sc->switch_in_progress 2175 && (cur_scp->smode.mode == VT_PROCESS) 2176 && cur_scp->proc) { 2177 p = pfind(cur_scp->pid); 2178 if (cur_scp->proc != p) { 2179 if (p) 2180 PROC_UNLOCK(p); 2181 /* 2182 * The controlling process has died!!. Do some clean up. 2183 * NOTE:`cur_scp->proc' and `cur_scp->smode.mode' 2184 * are not reset here yet; they will be cleared later. 2185 */ 2186 DPRINTF(5, ("cur_scp controlling process %d died, ", 2187 cur_scp->pid)); 2188 if (cur_scp->status & SWITCH_WAIT_REL) { 2189 /* 2190 * Force the previous switch to finish, but return now 2191 * with error. 2192 */ 2193 DPRINTF(5, ("reset WAIT_REL, ")); 2194 finish_vt_rel(cur_scp, TRUE, &s); 2195 splx(s); 2196 DPRINTF(5, ("finishing previous switch\n")); 2197 return EINVAL; 2198 } else if (cur_scp->status & SWITCH_WAIT_ACQ) { 2199 /* let's assume screen switch has been completed. */ 2200 DPRINTF(5, ("reset WAIT_ACQ, ")); 2201 finish_vt_acq(cur_scp); 2202 } else { 2203 /* 2204 * We are in between screen release and acquisition, and 2205 * reached here via scgetc() or scrn_timer() which has 2206 * interrupted exchange_scr(). Don't do anything stupid. 2207 */ 2208 DPRINTF(5, ("waiting nothing, ")); 2209 } 2210 } else { 2211 if (p) 2212 PROC_UNLOCK(p); 2213 /* 2214 * The controlling process is alive, but not responding... 2215 * It is either buggy or it may be just taking time. 2216 * The following code is a gross kludge to cope with this 2217 * problem for which there is no clean solution. XXX 2218 */ 2219 if (cur_scp->status & SWITCH_WAIT_REL) { 2220 switch (sc->switch_in_progress++) { 2221 case 1: 2222 break; 2223 case 2: 2224 DPRINTF(5, ("sending relsig again, ")); 2225 signal_vt_rel(cur_scp); 2226 break; 2227 case 3: 2228 break; 2229 case 4: 2230 default: 2231 /* 2232 * Act as if the controlling program returned 2233 * VT_FALSE. 2234 */ 2235 DPRINTF(5, ("force reset WAIT_REL, ")); 2236 finish_vt_rel(cur_scp, FALSE, &s); 2237 splx(s); 2238 DPRINTF(5, ("act as if VT_FALSE was seen\n")); 2239 return EINVAL; 2240 } 2241 } else if (cur_scp->status & SWITCH_WAIT_ACQ) { 2242 switch (sc->switch_in_progress++) { 2243 case 1: 2244 break; 2245 case 2: 2246 DPRINTF(5, ("sending acqsig again, ")); 2247 signal_vt_acq(cur_scp); 2248 break; 2249 case 3: 2250 break; 2251 case 4: 2252 default: 2253 /* clear the flag and finish the previous switch */ 2254 DPRINTF(5, ("force reset WAIT_ACQ, ")); 2255 finish_vt_acq(cur_scp); 2256 break; 2257 } 2258 } 2259 } 2260 } 2261 2262 /* 2263 * Return error if an invalid argument is given, or vty switch 2264 * is still in progress. 2265 */ 2266 if ((next_scr < sc->first_vty) || (next_scr >= sc->first_vty + sc->vtys) 2267 || sc->switch_in_progress) { 2268 splx(s); 2269 sc_bell(cur_scp, bios_value.bell_pitch, BELL_DURATION); 2270 DPRINTF(5, ("error 1\n")); 2271 return EINVAL; 2272 } 2273 2274 /* 2275 * Don't allow switching away from the graphics mode vty 2276 * if the switch mode is VT_AUTO, unless the next vty is the same 2277 * as the current or the current vty has been closed (but showing). 2278 */ 2279 tp = VIRTUAL_TTY(sc, cur_scp->index); 2280 if ((cur_scp->index != next_scr) 2281 && ISTTYOPEN(tp) 2282 && (cur_scp->smode.mode == VT_AUTO) 2283 && ISGRAPHSC(cur_scp)) { 2284 splx(s); 2285 sc_bell(cur_scp, bios_value.bell_pitch, BELL_DURATION); 2286 DPRINTF(5, ("error, graphics mode\n")); 2287 return EINVAL; 2288 } 2289 2290 /* 2291 * Is the wanted vty open? Don't allow switching to a closed vty. 2292 * If we are in DDB, don't switch to a vty in the VT_PROCESS mode. 2293 * Note that we always allow the user to switch to the kernel 2294 * console even if it is closed. 2295 */ 2296 if ((sc_console == NULL) || (next_scr != sc_console->index)) { 2297 tp = VIRTUAL_TTY(sc, next_scr); 2298 if (!ISTTYOPEN(tp)) { 2299 splx(s); 2300 sc_bell(cur_scp, bios_value.bell_pitch, BELL_DURATION); 2301 DPRINTF(5, ("error 2, requested vty isn't open!\n")); 2302 return EINVAL; 2303 } 2304 if ((debugger > 0) && (SC_STAT(tp->t_dev)->smode.mode == VT_PROCESS)) { 2305 splx(s); 2306 DPRINTF(5, ("error 3, requested vty is in the VT_PROCESS mode\n")); 2307 return EINVAL; 2308 } 2309 } 2310 2311 /* this is the start of vty switching process... */ 2312 ++sc->switch_in_progress; 2313 sc->delayed_next_scr = 0; 2314 sc->old_scp = cur_scp; 2315 sc->new_scp = sc_get_stat(SC_DEV(sc, next_scr)); 2316 if (sc->new_scp == sc->old_scp) { 2317 sc->switch_in_progress = 0; 2318 /* 2319 * XXX wakeup() calls mtx_lock(&sched_lock) which will hang if 2320 * sched_lock is in an in-between state, e.g., when we stop at 2321 * a breakpoint at fork_exit. It has always been wrong to call 2322 * wakeup() when the debugger is active. In RELENG_4, wakeup() 2323 * is supposed to be locked by splhigh(), but the debugger may 2324 * be invoked at splhigh(). 2325 */ 2326 if (debugger == 0) 2327 wakeup(&sc->new_scp->smode); 2328 splx(s); 2329 DPRINTF(5, ("switch done (new == old)\n")); 2330 return 0; 2331 } 2332 2333 /* has controlling process died? */ 2334 vt_proc_alive(sc->old_scp); 2335 vt_proc_alive(sc->new_scp); 2336 2337 /* wait for the controlling process to release the screen, if necessary */ 2338 if (signal_vt_rel(sc->old_scp)) { 2339 splx(s); 2340 return 0; 2341 } 2342 2343 /* go set up the new vty screen */ 2344 splx(s); 2345 exchange_scr(sc); 2346 s = spltty(); 2347 2348 /* wake up processes waiting for this vty */ 2349 if (debugger == 0) 2350 wakeup(&sc->cur_scp->smode); 2351 2352 /* wait for the controlling process to acknowledge, if necessary */ 2353 if (signal_vt_acq(sc->cur_scp)) { 2354 splx(s); 2355 return 0; 2356 } 2357 2358 sc->switch_in_progress = 0; 2359 if (sc->unit == sc_console_unit) 2360 cnavailable(sc_consptr, TRUE); 2361 splx(s); 2362 DPRINTF(5, ("switch done\n")); 2363 2364 return 0; 2365} 2366 2367static int 2368do_switch_scr(sc_softc_t *sc, int s) 2369{ 2370 vt_proc_alive(sc->new_scp); 2371 2372 splx(s); 2373 exchange_scr(sc); 2374 s = spltty(); 2375 /* sc->cur_scp == sc->new_scp */ 2376 wakeup(&sc->cur_scp->smode); 2377 2378 /* wait for the controlling process to acknowledge, if necessary */ 2379 if (!signal_vt_acq(sc->cur_scp)) { 2380 sc->switch_in_progress = 0; 2381 if (sc->unit == sc_console_unit) 2382 cnavailable(sc_consptr, TRUE); 2383 } 2384 2385 return s; 2386} 2387 2388static int 2389vt_proc_alive(scr_stat *scp) 2390{ 2391 struct proc *p; 2392 2393 if (scp->proc) { 2394 if ((p = pfind(scp->pid)) != NULL) 2395 PROC_UNLOCK(p); 2396 if (scp->proc == p) 2397 return TRUE; 2398 scp->proc = NULL; 2399 scp->smode.mode = VT_AUTO; 2400 DPRINTF(5, ("vt controlling process %d died\n", scp->pid)); 2401 } 2402 return FALSE; 2403} 2404 2405static int 2406signal_vt_rel(scr_stat *scp) 2407{ 2408 if (scp->smode.mode != VT_PROCESS) 2409 return FALSE; 2410 scp->status |= SWITCH_WAIT_REL; 2411 PROC_LOCK(scp->proc); 2412 psignal(scp->proc, scp->smode.relsig); 2413 PROC_UNLOCK(scp->proc); 2414 DPRINTF(5, ("sending relsig to %d\n", scp->pid)); 2415 return TRUE; 2416} 2417 2418static int 2419signal_vt_acq(scr_stat *scp) 2420{ 2421 if (scp->smode.mode != VT_PROCESS) 2422 return FALSE; 2423 if (scp->sc->unit == sc_console_unit) 2424 cnavailable(sc_consptr, FALSE); 2425 scp->status |= SWITCH_WAIT_ACQ; 2426 PROC_LOCK(scp->proc); 2427 psignal(scp->proc, scp->smode.acqsig); 2428 PROC_UNLOCK(scp->proc); 2429 DPRINTF(5, ("sending acqsig to %d\n", scp->pid)); 2430 return TRUE; 2431} 2432 2433static int 2434finish_vt_rel(scr_stat *scp, int release, int *s) 2435{ 2436 if (scp == scp->sc->old_scp && scp->status & SWITCH_WAIT_REL) { 2437 scp->status &= ~SWITCH_WAIT_REL; 2438 if (release) 2439 *s = do_switch_scr(scp->sc, *s); 2440 else 2441 scp->sc->switch_in_progress = 0; 2442 return 0; 2443 } 2444 return EINVAL; 2445} 2446 2447static int 2448finish_vt_acq(scr_stat *scp) 2449{ 2450 if (scp == scp->sc->new_scp && scp->status & SWITCH_WAIT_ACQ) { 2451 scp->status &= ~SWITCH_WAIT_ACQ; 2452 scp->sc->switch_in_progress = 0; 2453 return 0; 2454 } 2455 return EINVAL; 2456} 2457 2458static void 2459exchange_scr(sc_softc_t *sc) 2460{ 2461 scr_stat *scp; 2462 2463 /* save the current state of video and keyboard */ 2464 sc_move_cursor(sc->old_scp, sc->old_scp->xpos, sc->old_scp->ypos); 2465 if (!ISGRAPHSC(sc->old_scp)) 2466 sc_remove_cursor_image(sc->old_scp); 2467 if (sc->old_scp->kbd_mode == K_XLATE) 2468 save_kbd_state(sc->old_scp); 2469 2470 /* set up the video for the new screen */ 2471 scp = sc->cur_scp = sc->new_scp; 2472#ifdef PC98 2473 if (sc->old_scp->mode != scp->mode || ISUNKNOWNSC(sc->old_scp) || ISUNKNOWNSC(sc->new_scp)) 2474#else 2475 if (sc->old_scp->mode != scp->mode || ISUNKNOWNSC(sc->old_scp)) 2476#endif 2477 set_mode(scp); 2478#ifndef __sparc64__ 2479 else 2480 sc_vtb_init(&scp->scr, VTB_FRAMEBUFFER, scp->xsize, scp->ysize, 2481 (void *)sc->adp->va_window, FALSE); 2482#endif 2483 scp->status |= MOUSE_HIDDEN; 2484 sc_move_cursor(scp, scp->xpos, scp->ypos); 2485 if (!ISGRAPHSC(scp)) 2486 sc_set_cursor_image(scp); 2487#ifndef SC_NO_PALETTE_LOADING 2488 if (ISGRAPHSC(sc->old_scp)) 2489 load_palette(sc->adp, sc->palette); 2490#endif 2491 sc_set_border(scp, scp->border); 2492 2493 /* set up the keyboard for the new screen */ 2494 if (sc->old_scp->kbd_mode != scp->kbd_mode) 2495 kbd_ioctl(sc->kbd, KDSKBMODE, (caddr_t)&scp->kbd_mode); 2496 update_kbd_state(scp, scp->status, LOCK_MASK); 2497 2498 mark_all(scp); 2499} 2500 2501void 2502sc_puts(scr_stat *scp, u_char *buf, int len) 2503{ 2504#ifdef DEV_SPLASH 2505 /* make screensaver happy */ 2506 if (!sticky_splash && scp == scp->sc->cur_scp && !sc_saver_keyb_only) 2507 run_scrn_saver = FALSE; 2508#endif 2509 2510 if (scp->tsw) 2511 (*scp->tsw->te_puts)(scp, buf, len); 2512 2513 if (scp->sc->delayed_next_scr) 2514 sc_switch_scr(scp->sc, scp->sc->delayed_next_scr - 1); 2515} 2516 2517void 2518sc_draw_cursor_image(scr_stat *scp) 2519{ 2520 /* assert(scp == scp->sc->cur_scp); */ 2521 ++scp->sc->videoio_in_progress; 2522 (*scp->rndr->draw_cursor)(scp, scp->cursor_pos, 2523 scp->curs_attr.flags & CONS_BLINK_CURSOR, TRUE, 2524 sc_inside_cutmark(scp, scp->cursor_pos)); 2525 scp->cursor_oldpos = scp->cursor_pos; 2526 --scp->sc->videoio_in_progress; 2527} 2528 2529void 2530sc_remove_cursor_image(scr_stat *scp) 2531{ 2532 /* assert(scp == scp->sc->cur_scp); */ 2533 ++scp->sc->videoio_in_progress; 2534 (*scp->rndr->draw_cursor)(scp, scp->cursor_oldpos, 2535 scp->curs_attr.flags & CONS_BLINK_CURSOR, FALSE, 2536 sc_inside_cutmark(scp, scp->cursor_oldpos)); 2537 --scp->sc->videoio_in_progress; 2538} 2539 2540static void 2541update_cursor_image(scr_stat *scp) 2542{ 2543 /* assert(scp == scp->sc->cur_scp); */ 2544 sc_remove_cursor_image(scp); 2545 sc_set_cursor_image(scp); 2546 sc_draw_cursor_image(scp); 2547} 2548 2549void 2550sc_set_cursor_image(scr_stat *scp) 2551{ 2552 scp->curs_attr.flags = scp->curr_curs_attr.flags; 2553 if (scp->curs_attr.flags & CONS_HIDDEN_CURSOR) { 2554 /* hidden cursor is internally represented as zero-height underline */ 2555 scp->curs_attr.flags = CONS_CHAR_CURSOR; 2556 scp->curs_attr.base = scp->curs_attr.height = 0; 2557 } else if (scp->curs_attr.flags & CONS_CHAR_CURSOR) { 2558 scp->curs_attr.base = imin(scp->curr_curs_attr.base, 2559 scp->font_size - 1); 2560 scp->curs_attr.height = imin(scp->curr_curs_attr.height, 2561 scp->font_size - scp->curs_attr.base); 2562 } else { /* block cursor */ 2563 scp->curs_attr.base = 0; 2564 scp->curs_attr.height = scp->font_size; 2565 } 2566 2567 /* assert(scp == scp->sc->cur_scp); */ 2568 ++scp->sc->videoio_in_progress; 2569 (*scp->rndr->set_cursor)(scp, scp->curs_attr.base, scp->curs_attr.height, 2570 scp->curs_attr.flags & CONS_BLINK_CURSOR); 2571 --scp->sc->videoio_in_progress; 2572} 2573 2574static void 2575change_cursor_shape(scr_stat *scp, int flags, int base, int height) 2576{ 2577 if ((scp == scp->sc->cur_scp) && !ISGRAPHSC(scp)) 2578 sc_remove_cursor_image(scp); 2579 2580 if (base >= 0) 2581 scp->curr_curs_attr.base = base; 2582 if (height >= 0) 2583 scp->curr_curs_attr.height = height; 2584 if (flags & CONS_RESET_CURSOR) 2585 scp->curr_curs_attr = scp->dflt_curs_attr; 2586 else 2587 scp->curr_curs_attr.flags = flags & CONS_CURSOR_ATTRS; 2588 2589 if ((scp == scp->sc->cur_scp) && !ISGRAPHSC(scp)) { 2590 sc_set_cursor_image(scp); 2591 sc_draw_cursor_image(scp); 2592 } 2593} 2594 2595void 2596sc_change_cursor_shape(scr_stat *scp, int flags, int base, int height) 2597{ 2598 sc_softc_t *sc; 2599 struct cdev *dev; 2600 int s; 2601 int i; 2602 2603 s = spltty(); 2604 if ((flags != -1) && (flags & CONS_LOCAL_CURSOR)) { 2605 /* local (per vty) change */ 2606 change_cursor_shape(scp, flags, base, height); 2607 splx(s); 2608 return; 2609 } 2610 2611 /* global change */ 2612 sc = scp->sc; 2613 if (base >= 0) 2614 sc->curs_attr.base = base; 2615 if (height >= 0) 2616 sc->curs_attr.height = height; 2617 if (flags != -1) { 2618 if (flags & CONS_RESET_CURSOR) 2619 sc->curs_attr = sc->dflt_curs_attr; 2620 else 2621 sc->curs_attr.flags = flags & CONS_CURSOR_ATTRS; 2622 } 2623 2624 for (i = sc->first_vty; i < sc->first_vty + sc->vtys; ++i) {
| 31 32#include "opt_syscons.h" 33#include "opt_splash.h" 34#include "opt_ddb.h" 35 36#include <sys/param.h> 37#include <sys/systm.h> 38#include <sys/conf.h> 39#include <sys/cons.h> 40#include <sys/consio.h> 41#include <sys/eventhandler.h> 42#include <sys/fbio.h> 43#include <sys/kbio.h> 44#include <sys/kernel.h> 45#include <sys/lock.h> 46#include <sys/malloc.h> 47#include <sys/mutex.h> 48#include <sys/proc.h> 49#include <sys/random.h> 50#include <sys/reboot.h> 51#include <sys/signalvar.h> 52#include <sys/sysctl.h> 53#include <sys/tty.h> 54#include <sys/power.h> 55 56#include <machine/clock.h> 57#if __sparc64__ || __powerpc__ 58#include <machine/sc_machdep.h> 59#else 60#include <machine/pc/display.h> 61#endif 62#ifdef __i386__ 63#include <machine/psl.h> 64#include <machine/apm_bios.h> 65#include <machine/frame.h> 66#endif 67 68#include <dev/kbd/kbdreg.h> 69#include <dev/fb/fbreg.h> 70#include <dev/fb/splashreg.h> 71#include <dev/syscons/syscons.h> 72 73#define COLD 0 74#define WARM 1 75 76#define DEFAULT_BLANKTIME (5*60) /* 5 minutes */ 77#define MAX_BLANKTIME (7*24*60*60) /* 7 days!? */ 78 79#define KEYCODE_BS 0x0e /* "<-- Backspace" key, XXX */ 80 81typedef struct default_attr { 82 int std_color; /* normal hardware color */ 83 int rev_color; /* reverse hardware color */ 84} default_attr; 85 86static default_attr user_default = { 87 SC_NORM_ATTR, 88 SC_NORM_REV_ATTR, 89}; 90 91static default_attr kernel_default = { 92 SC_KERNEL_CONS_ATTR, 93 SC_KERNEL_CONS_REV_ATTR, 94}; 95 96static int sc_console_unit = -1; 97static int sc_saver_keyb_only = 1; 98static scr_stat *sc_console; 99static struct tty *sc_console_tty; 100static struct consdev *sc_consptr; 101static void *kernel_console_ts; 102static scr_stat main_console; 103static struct cdev *main_devs[MAXCONS]; 104 105static char init_done = COLD; 106static char shutdown_in_progress = FALSE; 107static char sc_malloc = FALSE; 108 109static int saver_mode = CONS_NO_SAVER; /* LKM/user saver */ 110static int run_scrn_saver = FALSE; /* should run the saver? */ 111static int enable_bell = TRUE; /* enable beeper */ 112static long scrn_blank_time = 0; /* screen saver timeout value */ 113#ifdef DEV_SPLASH 114static int scrn_blanked; /* # of blanked screen */ 115static int sticky_splash = FALSE; 116 117static void none_saver(sc_softc_t *sc, int blank) { } 118static void (*current_saver)(sc_softc_t *, int) = none_saver; 119#endif 120 121SYSCTL_NODE(_hw, OID_AUTO, syscons, CTLFLAG_RD, 0, "syscons"); 122SYSCTL_NODE(_hw_syscons, OID_AUTO, saver, CTLFLAG_RD, 0, "saver"); 123SYSCTL_INT(_hw_syscons_saver, OID_AUTO, keybonly, CTLFLAG_RW, 124 &sc_saver_keyb_only, 0, "screen saver interrupted by input only"); 125SYSCTL_INT(_hw_syscons, OID_AUTO, bell, CTLFLAG_RW, &enable_bell, 126 0, "enable bell"); 127#if !defined(SC_NO_FONT_LOADING) && defined(SC_DFLT_FONT) 128#include "font.h" 129#endif 130 131 d_ioctl_t *sc_user_ioctl; 132 133static bios_values_t bios_value; 134 135static int enable_panic_key; 136SYSCTL_INT(_machdep, OID_AUTO, enable_panic_key, CTLFLAG_RW, &enable_panic_key, 137 0, ""); 138 139#define SC_CONSOLECTL 255 140 141#define VIRTUAL_TTY(sc, x) (SC_DEV((sc), (x)) != NULL ? \ 142 SC_DEV((sc), (x))->si_tty : NULL) 143#define ISTTYOPEN(tp) ((tp) && ((tp)->t_state & TS_ISOPEN)) 144 145static int debugger; 146 147/* prototypes */ 148static int scvidprobe(int unit, int flags, int cons); 149static int sckbdprobe(int unit, int flags, int cons); 150static void scmeminit(void *arg); 151static int scdevtounit(struct cdev *dev); 152static kbd_callback_func_t sckbdevent; 153static int scparam(struct tty *tp, struct termios *t); 154static void scstart(struct tty *tp); 155static void scinit(int unit, int flags); 156static scr_stat *sc_get_stat(struct cdev *devptr); 157#if !__alpha__ 158static void scterm(int unit, int flags); 159#endif 160static void scshutdown(void *arg, int howto); 161static u_int scgetc(sc_softc_t *sc, u_int flags); 162#define SCGETC_CN 1 163#define SCGETC_NONBLOCK 2 164static int sccngetch(int flags); 165static void sccnupdate(scr_stat *scp); 166static scr_stat *alloc_scp(sc_softc_t *sc, int vty); 167static void init_scp(sc_softc_t *sc, int vty, scr_stat *scp); 168static timeout_t scrn_timer; 169static int and_region(int *s1, int *e1, int s2, int e2); 170static void scrn_update(scr_stat *scp, int show_cursor); 171 172#ifdef DEV_SPLASH 173static int scsplash_callback(int event, void *arg); 174static void scsplash_saver(sc_softc_t *sc, int show); 175static int add_scrn_saver(void (*this_saver)(sc_softc_t *, int)); 176static int remove_scrn_saver(void (*this_saver)(sc_softc_t *, int)); 177static int set_scrn_saver_mode(scr_stat *scp, int mode, u_char *pal, int border); 178static int restore_scrn_saver_mode(scr_stat *scp, int changemode); 179static void stop_scrn_saver(sc_softc_t *sc, void (*saver)(sc_softc_t *, int)); 180static int wait_scrn_saver_stop(sc_softc_t *sc); 181#define scsplash_stick(stick) (sticky_splash = (stick)) 182#else /* !DEV_SPLASH */ 183#define scsplash_stick(stick) 184#endif /* DEV_SPLASH */ 185 186static int do_switch_scr(sc_softc_t *sc, int s); 187static int vt_proc_alive(scr_stat *scp); 188static int signal_vt_rel(scr_stat *scp); 189static int signal_vt_acq(scr_stat *scp); 190static int finish_vt_rel(scr_stat *scp, int release, int *s); 191static int finish_vt_acq(scr_stat *scp); 192static void exchange_scr(sc_softc_t *sc); 193static void update_cursor_image(scr_stat *scp); 194static void change_cursor_shape(scr_stat *scp, int flags, int base, int height); 195static int save_kbd_state(scr_stat *scp); 196static int update_kbd_state(scr_stat *scp, int state, int mask); 197static int update_kbd_leds(scr_stat *scp, int which); 198static timeout_t blink_screen; 199 200static cn_probe_t sccnprobe; 201static cn_init_t sccninit; 202static cn_getc_t sccngetc; 203static cn_checkc_t sccncheckc; 204static cn_putc_t sccnputc; 205static cn_dbctl_t sccndbctl; 206static cn_term_t sccnterm; 207 208#if __alpha__ 209void sccnattach(void); 210#endif 211 212CONS_DRIVER(sc, sccnprobe, sccninit, sccnterm, sccngetc, sccncheckc, sccnputc, 213 sccndbctl); 214 215static d_open_t scopen; 216static d_close_t scclose; 217static d_read_t scread; 218static d_ioctl_t scioctl; 219static d_mmap_t scmmap; 220 221static struct cdevsw sc_cdevsw = { 222 .d_version = D_VERSION, 223 .d_open = scopen, 224 .d_close = scclose, 225 .d_read = scread, 226 .d_ioctl = scioctl, 227 .d_mmap = scmmap, 228 .d_name = "sc", 229 .d_flags = D_TTY | D_NEEDGIANT, 230}; 231 232int 233sc_probe_unit(int unit, int flags) 234{ 235 if (!scvidprobe(unit, flags, FALSE)) { 236 if (bootverbose) 237 printf("sc%d: no video adapter found.\n", unit); 238 return ENXIO; 239 } 240 241 /* syscons will be attached even when there is no keyboard */ 242 sckbdprobe(unit, flags, FALSE); 243 244 return 0; 245} 246 247/* probe video adapters, return TRUE if found */ 248static int 249scvidprobe(int unit, int flags, int cons) 250{ 251 /* 252 * Access the video adapter driver through the back door! 253 * Video adapter drivers need to be configured before syscons. 254 * However, when syscons is being probed as the low-level console, 255 * they have not been initialized yet. We force them to initialize 256 * themselves here. XXX 257 */ 258 vid_configure(cons ? VIO_PROBE_ONLY : 0); 259 260 return (vid_find_adapter("*", unit) >= 0); 261} 262 263/* probe the keyboard, return TRUE if found */ 264static int 265sckbdprobe(int unit, int flags, int cons) 266{ 267 /* access the keyboard driver through the backdoor! */ 268 kbd_configure(cons ? KB_CONF_PROBE_ONLY : 0); 269 270 return (kbd_find_keyboard("*", unit) >= 0); 271} 272 273static char 274*adapter_name(video_adapter_t *adp) 275{ 276 static struct { 277 int type; 278 char *name[2]; 279 } names[] = { 280 { KD_MONO, { "MDA", "MDA" } }, 281 { KD_HERCULES, { "Hercules", "Hercules" } }, 282 { KD_CGA, { "CGA", "CGA" } }, 283 { KD_EGA, { "EGA", "EGA (mono)" } }, 284 { KD_VGA, { "VGA", "VGA (mono)" } }, 285 { KD_PC98, { "PC-98x1", "PC-98x1" } }, 286 { KD_TGA, { "TGA", "TGA" } }, 287 { -1, { "Unknown", "Unknown" } }, 288 }; 289 int i; 290 291 for (i = 0; names[i].type != -1; ++i) 292 if (names[i].type == adp->va_type) 293 break; 294 return names[i].name[(adp->va_flags & V_ADP_COLOR) ? 0 : 1]; 295} 296 297int 298sc_attach_unit(int unit, int flags) 299{ 300 sc_softc_t *sc; 301 scr_stat *scp; 302#ifdef SC_PIXEL_MODE 303 video_info_t info; 304#endif 305 int vc; 306 struct cdev *dev; 307 308 flags &= ~SC_KERNEL_CONSOLE; 309 310 if (sc_console_unit == unit) { 311 /* 312 * If this unit is being used as the system console, we need to 313 * adjust some variables and buffers before and after scinit(). 314 */ 315 /* assert(sc_console != NULL) */ 316 flags |= SC_KERNEL_CONSOLE; 317 scmeminit(NULL); 318 319 scinit(unit, flags); 320 321 if (sc_console->tsw->te_size > 0) { 322 /* assert(sc_console->ts != NULL); */ 323 kernel_console_ts = sc_console->ts; 324 sc_console->ts = malloc(sc_console->tsw->te_size, 325 M_DEVBUF, M_WAITOK); 326 bcopy(kernel_console_ts, sc_console->ts, sc_console->tsw->te_size); 327 (*sc_console->tsw->te_default_attr)(sc_console, 328 user_default.std_color, 329 user_default.rev_color); 330 } 331 } else { 332 scinit(unit, flags); 333 } 334 335 sc = sc_get_softc(unit, flags & SC_KERNEL_CONSOLE); 336 sc->config = flags; 337 scp = sc_get_stat(sc->dev[0]); 338 if (sc_console == NULL) /* sc_console_unit < 0 */ 339 sc_console = scp; 340 341#ifdef SC_PIXEL_MODE 342 if ((sc->config & SC_VESA800X600) 343 && ((*vidsw[sc->adapter]->get_info)(sc->adp, M_VESA_800x600, &info) == 0)) { 344#ifdef DEV_SPLASH 345 if (sc->flags & SC_SPLASH_SCRN) 346 splash_term(sc->adp); 347#endif 348 sc_set_graphics_mode(scp, NULL, M_VESA_800x600); 349 sc_set_pixel_mode(scp, NULL, COL, ROW, 16); 350 sc->initial_mode = M_VESA_800x600; 351#ifdef DEV_SPLASH 352 /* put up the splash again! */ 353 if (sc->flags & SC_SPLASH_SCRN) 354 splash_init(sc->adp, scsplash_callback, sc); 355#endif 356 } 357#endif /* SC_PIXEL_MODE */ 358 359 /* initialize cursor */ 360 if (!ISGRAPHSC(scp)) 361 update_cursor_image(scp); 362 363 /* get screen update going */ 364 scrn_timer(sc); 365 366 /* set up the keyboard */ 367 kbd_ioctl(sc->kbd, KDSKBMODE, (caddr_t)&scp->kbd_mode); 368 update_kbd_state(scp, scp->status, LOCK_MASK); 369 370 printf("sc%d: %s <%d virtual consoles, flags=0x%x>\n", 371 unit, adapter_name(sc->adp), sc->vtys, sc->config); 372 if (bootverbose) { 373 printf("sc%d:", unit); 374 if (sc->adapter >= 0) 375 printf(" fb%d", sc->adapter); 376 if (sc->keyboard >= 0) 377 printf(", kbd%d", sc->keyboard); 378 if (scp->tsw) 379 printf(", terminal emulator: %s (%s)", 380 scp->tsw->te_name, scp->tsw->te_desc); 381 printf("\n"); 382 } 383 384 /* register a shutdown callback for the kernel console */ 385 if (sc_console_unit == unit) 386 EVENTHANDLER_REGISTER(shutdown_pre_sync, scshutdown, 387 (void *)(uintptr_t)unit, SHUTDOWN_PRI_DEFAULT); 388 389 for (vc = 0; vc < sc->vtys; vc++) { 390 if (sc->dev[vc] == NULL) { 391 dev = make_dev(&sc_cdevsw, vc + unit * MAXCONS, 392 UID_ROOT, GID_WHEEL, 0600, "ttyv%r", vc + unit * MAXCONS); 393 sc->dev[vc] = dev; 394 sc->dev[vc]->si_tty = ttymalloc(sc->dev[vc]->si_tty); 395 if (vc == 0 && sc->dev == main_devs) 396 SC_STAT(sc->dev[0]) = &main_console; 397 } 398 /* 399 * The first vty already has struct tty and scr_stat initialized 400 * in scinit(). The other vtys will have these structs when 401 * first opened. 402 */ 403 } 404 405 dev = make_dev(&sc_cdevsw, SC_CONSOLECTL, 406 UID_ROOT, GID_WHEEL, 0600, "consolectl"); 407 dev->si_tty = sc_console_tty = ttymalloc(sc_console_tty); 408 SC_STAT(dev) = sc_console; 409 410 return 0; 411} 412 413static void 414scmeminit(void *arg) 415{ 416 if (sc_malloc) 417 return; 418 sc_malloc = TRUE; 419 420 /* 421 * As soon as malloc() becomes functional, we had better allocate 422 * various buffers for the kernel console. 423 */ 424 425 if (sc_console_unit < 0) /* sc_console == NULL */ 426 return; 427 428 /* copy the temporary buffer to the final buffer */ 429 sc_alloc_scr_buffer(sc_console, FALSE, FALSE); 430 431#ifndef SC_NO_CUTPASTE 432 sc_alloc_cut_buffer(sc_console, FALSE); 433#endif 434 435#ifndef SC_NO_HISTORY 436 /* initialize history buffer & pointers */ 437 sc_alloc_history_buffer(sc_console, 0, 0, FALSE); 438#endif 439} 440 441/* XXX */ 442SYSINIT(sc_mem, SI_SUB_KMEM, SI_ORDER_ANY, scmeminit, NULL); 443 444static int 445scdevtounit(struct cdev *dev) 446{ 447 int vty = SC_VTY(dev); 448 449 if (vty == SC_CONSOLECTL) 450 return ((sc_console != NULL) ? sc_console->sc->unit : -1); 451 else if ((vty < 0) || (vty >= MAXCONS*sc_max_unit())) 452 return -1; 453 else 454 return vty/MAXCONS; 455} 456 457static int 458scopen(struct cdev *dev, int flag, int mode, struct thread *td) 459{ 460 int unit = scdevtounit(dev); 461 sc_softc_t *sc; 462 struct tty *tp; 463 scr_stat *scp; 464#ifndef __sparc64__ 465 keyarg_t key; 466#endif 467 int error; 468 469 DPRINTF(5, ("scopen: dev:%d,%d, unit:%d, vty:%d\n", 470 major(dev), minor(dev), unit, SC_VTY(dev))); 471 472 sc = sc_get_softc(unit, (sc_console_unit == unit) ? SC_KERNEL_CONSOLE : 0); 473 if (sc == NULL) 474 return ENXIO; 475 476 tp = dev->si_tty = ttymalloc(dev->si_tty); 477 tp->t_oproc = scstart; 478 tp->t_param = scparam; 479 tp->t_stop = nottystop; 480 tp->t_dev = dev; 481 if (!ISTTYOPEN(tp)) { 482 ttychars(tp); 483 /* Use the current setting of the <-- key as default VERASE. */ 484 /* If the Delete key is preferable, an stty is necessary */ 485#ifndef __sparc64__ 486 if (sc->kbd != NULL) { 487 key.keynum = KEYCODE_BS; 488 kbd_ioctl(sc->kbd, GIO_KEYMAPENT, (caddr_t)&key); 489 tp->t_cc[VERASE] = key.key.map[0]; 490 } 491#endif 492 tp->t_iflag = TTYDEF_IFLAG; 493 tp->t_oflag = TTYDEF_OFLAG; 494 tp->t_cflag = TTYDEF_CFLAG; 495 tp->t_lflag = TTYDEF_LFLAG; 496 tp->t_ispeed = tp->t_ospeed = TTYDEF_SPEED; 497 scparam(tp, &tp->t_termios); 498 ttyld_modem(tp, 1); 499 } 500 else 501 if (tp->t_state & TS_XCLUDE && suser(td)) 502 return(EBUSY); 503 504 error = ttyld_open(tp, dev); 505 506 scp = sc_get_stat(dev); 507 if (scp == NULL) { 508 scp = SC_STAT(dev) = alloc_scp(sc, SC_VTY(dev)); 509 if (ISGRAPHSC(scp)) 510 sc_set_pixel_mode(scp, NULL, COL, ROW, 16); 511 } 512 if (!tp->t_winsize.ws_col && !tp->t_winsize.ws_row) { 513 tp->t_winsize.ws_col = scp->xsize; 514 tp->t_winsize.ws_row = scp->ysize; 515 } 516 517 return error; 518} 519 520static int 521scclose(struct cdev *dev, int flag, int mode, struct thread *td) 522{ 523 struct tty *tp = dev->si_tty; 524 scr_stat *scp; 525 int s; 526 527 if (SC_VTY(dev) != SC_CONSOLECTL) { 528 scp = sc_get_stat(tp->t_dev); 529 /* were we in the middle of the VT switching process? */ 530 DPRINTF(5, ("sc%d: scclose(), ", scp->sc->unit)); 531 s = spltty(); 532 if ((scp == scp->sc->cur_scp) && (scp->sc->unit == sc_console_unit)) 533 cnavailable(sc_consptr, TRUE); 534 if (finish_vt_rel(scp, TRUE, &s) == 0) /* force release */ 535 DPRINTF(5, ("reset WAIT_REL, ")); 536 if (finish_vt_acq(scp) == 0) /* force acknowledge */ 537 DPRINTF(5, ("reset WAIT_ACQ, ")); 538#if not_yet_done 539 if (scp == &main_console) { 540 scp->pid = 0; 541 scp->proc = NULL; 542 scp->smode.mode = VT_AUTO; 543 } 544 else { 545 sc_vtb_destroy(&scp->vtb); 546#ifndef __sparc64__ 547 sc_vtb_destroy(&scp->scr); 548#endif 549 sc_free_history_buffer(scp, scp->ysize); 550 SC_STAT(dev) = NULL; 551 free(scp, M_DEVBUF); 552 } 553#else 554 scp->pid = 0; 555 scp->proc = NULL; 556 scp->smode.mode = VT_AUTO; 557#endif 558 scp->kbd_mode = K_XLATE; 559 if (scp == scp->sc->cur_scp) 560 kbd_ioctl(scp->sc->kbd, KDSKBMODE, (caddr_t)&scp->kbd_mode); 561 DPRINTF(5, ("done.\n")); 562 } 563 spltty(); 564 ttyld_close(tp, flag); 565 ttyclose(tp); 566 spl0(); 567 return(0); 568} 569 570static int 571scread(struct cdev *dev, struct uio *uio, int flag) 572{ 573 if (!sc_saver_keyb_only) 574 sc_touch_scrn_saver(); 575 return ttyread(dev, uio, flag); 576} 577 578static int 579sckbdevent(keyboard_t *thiskbd, int event, void *arg) 580{ 581 sc_softc_t *sc; 582 struct tty *cur_tty; 583 int c; 584 size_t len; 585 u_char *cp; 586 587 sc = (sc_softc_t *)arg; 588 /* assert(thiskbd == sc->kbd) */ 589 590 switch (event) { 591 case KBDIO_KEYINPUT: 592 break; 593 case KBDIO_UNLOADING: 594 sc->kbd = NULL; 595 sc->keyboard = -1; 596 kbd_release(thiskbd, (void *)&sc->keyboard); 597 return 0; 598 default: 599 return EINVAL; 600 } 601 602 /* 603 * Loop while there is still input to get from the keyboard. 604 * I don't think this is nessesary, and it doesn't fix 605 * the Xaccel-2.1 keyboard hang, but it can't hurt. XXX 606 */ 607 while ((c = scgetc(sc, SCGETC_NONBLOCK)) != NOKEY) { 608 609 cur_tty = VIRTUAL_TTY(sc, sc->cur_scp->index); 610 if (!ISTTYOPEN(cur_tty)) { 611 cur_tty = sc_console_tty; 612 if (!ISTTYOPEN(cur_tty)) 613 continue; 614 } 615 616 if ((*sc->cur_scp->tsw->te_input)(sc->cur_scp, c, cur_tty)) 617 continue; 618 619 switch (KEYFLAGS(c)) { 620 case 0x0000: /* normal key */ 621 ttyld_rint(cur_tty, KEYCHAR(c)); 622 break; 623 case FKEY: /* function key, return string */ 624 cp = kbd_get_fkeystr(thiskbd, KEYCHAR(c), &len); 625 if (cp != NULL) { 626 while (len-- > 0) 627 ttyld_rint(cur_tty, *cp++); 628 } 629 break; 630 case MKEY: /* meta is active, prepend ESC */ 631 ttyld_rint(cur_tty, 0x1b); 632 ttyld_rint(cur_tty, KEYCHAR(c)); 633 break; 634 case BKEY: /* backtab fixed sequence (esc [ Z) */ 635 ttyld_rint(cur_tty, 0x1b); 636 ttyld_rint(cur_tty, '['); 637 ttyld_rint(cur_tty, 'Z'); 638 break; 639 } 640 } 641 642 sc->cur_scp->status |= MOUSE_HIDDEN; 643 644 return 0; 645} 646 647static int 648scparam(struct tty *tp, struct termios *t) 649{ 650 tp->t_ispeed = t->c_ispeed; 651 tp->t_ospeed = t->c_ospeed; 652 tp->t_cflag = t->c_cflag; 653 return 0; 654} 655 656static int 657scioctl(struct cdev *dev, u_long cmd, caddr_t data, int flag, struct thread *td) 658{ 659 int error; 660 int i; 661 struct tty *tp; 662 sc_softc_t *sc; 663 scr_stat *scp; 664 int s; 665 666 tp = dev->si_tty; 667 668 /* If there is a user_ioctl function call that first */ 669 if (sc_user_ioctl) { 670 error = (*sc_user_ioctl)(dev, cmd, data, flag, td); 671 if (error != ENOIOCTL) 672 return error; 673 } 674 675 error = sc_vid_ioctl(tp, cmd, data, flag, td); 676 if (error != ENOIOCTL) 677 return error; 678 679#ifndef SC_NO_HISTORY 680 error = sc_hist_ioctl(tp, cmd, data, flag, td); 681 if (error != ENOIOCTL) 682 return error; 683#endif 684 685#ifndef SC_NO_SYSMOUSE 686 error = sc_mouse_ioctl(tp, cmd, data, flag, td); 687 if (error != ENOIOCTL) 688 return error; 689#endif 690 691 scp = sc_get_stat(tp->t_dev); 692 /* assert(scp != NULL) */ 693 /* scp is sc_console, if SC_VTY(dev) == SC_CONSOLECTL. */ 694 sc = scp->sc; 695 696 if (scp->tsw) { 697 error = (*scp->tsw->te_ioctl)(scp, tp, cmd, data, flag, td); 698 if (error != ENOIOCTL) 699 return error; 700 } 701 702 switch (cmd) { /* process console hardware related ioctl's */ 703 704 case GIO_ATTR: /* get current attributes */ 705 /* this ioctl is not processed here, but in the terminal emulator */ 706 return ENOTTY; 707 708 case GIO_COLOR: /* is this a color console ? */ 709 *(int *)data = (sc->adp->va_flags & V_ADP_COLOR) ? 1 : 0; 710 return 0; 711 712 case CONS_BLANKTIME: /* set screen saver timeout (0 = no saver) */ 713 if (*(int *)data < 0 || *(int *)data > MAX_BLANKTIME) 714 return EINVAL; 715 s = spltty(); 716 scrn_blank_time = *(int *)data; 717 run_scrn_saver = (scrn_blank_time != 0); 718 splx(s); 719 return 0; 720 721 case CONS_CURSORTYPE: /* set cursor type (obsolete) */ 722 s = spltty(); 723 *(int *)data &= CONS_CURSOR_ATTRS; 724 sc_change_cursor_shape(scp, *(int *)data, -1, -1); 725 splx(s); 726 return 0; 727 728 case CONS_GETCURSORSHAPE: /* get cursor shape (new interface) */ 729 if (((int *)data)[0] & CONS_LOCAL_CURSOR) { 730 ((int *)data)[0] = scp->curr_curs_attr.flags; 731 ((int *)data)[1] = scp->curr_curs_attr.base; 732 ((int *)data)[2] = scp->curr_curs_attr.height; 733 } else { 734 ((int *)data)[0] = sc->curs_attr.flags; 735 ((int *)data)[1] = sc->curs_attr.base; 736 ((int *)data)[2] = sc->curs_attr.height; 737 } 738 return 0; 739 740 case CONS_SETCURSORSHAPE: /* set cursor shape (new interface) */ 741 s = spltty(); 742 sc_change_cursor_shape(scp, ((int *)data)[0], 743 ((int *)data)[1], ((int *)data)[2]); 744 splx(s); 745 return 0; 746 747 case CONS_BELLTYPE: /* set bell type sound/visual */ 748 if ((*(int *)data) & 0x01) 749 sc->flags |= SC_VISUAL_BELL; 750 else 751 sc->flags &= ~SC_VISUAL_BELL; 752 if ((*(int *)data) & 0x02) 753 sc->flags |= SC_QUIET_BELL; 754 else 755 sc->flags &= ~SC_QUIET_BELL; 756 return 0; 757 758 case CONS_GETINFO: /* get current (virtual) console info */ 759 { 760 vid_info_t *ptr = (vid_info_t*)data; 761 if (ptr->size == sizeof(struct vid_info)) { 762 ptr->m_num = sc->cur_scp->index; 763 ptr->font_size = scp->font_size; 764 ptr->mv_col = scp->xpos; 765 ptr->mv_row = scp->ypos; 766 ptr->mv_csz = scp->xsize; 767 ptr->mv_rsz = scp->ysize; 768 ptr->mv_hsz = (scp->history != NULL) ? scp->history->vtb_rows : 0; 769 /* 770 * The following fields are filled by the terminal emulator. XXX 771 * 772 * ptr->mv_norm.fore 773 * ptr->mv_norm.back 774 * ptr->mv_rev.fore 775 * ptr->mv_rev.back 776 */ 777 ptr->mv_grfc.fore = 0; /* not supported */ 778 ptr->mv_grfc.back = 0; /* not supported */ 779 ptr->mv_ovscan = scp->border; 780 if (scp == sc->cur_scp) 781 save_kbd_state(scp); 782 ptr->mk_keylock = scp->status & LOCK_MASK; 783 return 0; 784 } 785 return EINVAL; 786 } 787 788 case CONS_GETVERS: /* get version number */ 789 *(int*)data = 0x200; /* version 2.0 */ 790 return 0; 791 792 case CONS_IDLE: /* see if the screen has been idle */ 793 /* 794 * When the screen is in the GRAPHICS_MODE or UNKNOWN_MODE, 795 * the user process may have been writing something on the 796 * screen and syscons is not aware of it. Declare the screen 797 * is NOT idle if it is in one of these modes. But there is 798 * an exception to it; if a screen saver is running in the 799 * graphics mode in the current screen, we should say that the 800 * screen has been idle. 801 */ 802 *(int *)data = (sc->flags & SC_SCRN_IDLE) 803 && (!ISGRAPHSC(sc->cur_scp) 804 || (sc->cur_scp->status & SAVER_RUNNING)); 805 return 0; 806 807 case CONS_SAVERMODE: /* set saver mode */ 808 switch(*(int *)data) { 809 case CONS_NO_SAVER: 810 case CONS_USR_SAVER: 811 /* if a LKM screen saver is running, stop it first. */ 812 scsplash_stick(FALSE); 813 saver_mode = *(int *)data; 814 s = spltty(); 815#ifdef DEV_SPLASH 816 if ((error = wait_scrn_saver_stop(NULL))) { 817 splx(s); 818 return error; 819 } 820#endif 821 run_scrn_saver = TRUE; 822 if (saver_mode == CONS_USR_SAVER) 823 scp->status |= SAVER_RUNNING; 824 else 825 scp->status &= ~SAVER_RUNNING; 826 scsplash_stick(TRUE); 827 splx(s); 828 break; 829 case CONS_LKM_SAVER: 830 s = spltty(); 831 if ((saver_mode == CONS_USR_SAVER) && (scp->status & SAVER_RUNNING)) 832 scp->status &= ~SAVER_RUNNING; 833 saver_mode = *(int *)data; 834 splx(s); 835 break; 836 default: 837 return EINVAL; 838 } 839 return 0; 840 841 case CONS_SAVERSTART: /* immediately start/stop the screen saver */ 842 /* 843 * Note that this ioctl does not guarantee the screen saver 844 * actually starts or stops. It merely attempts to do so... 845 */ 846 s = spltty(); 847 run_scrn_saver = (*(int *)data != 0); 848 if (run_scrn_saver) 849 sc->scrn_time_stamp -= scrn_blank_time; 850 splx(s); 851 return 0; 852 853 case CONS_SCRSHOT: /* get a screen shot */ 854 { 855 int retval, hist_rsz; 856 size_t lsize, csize; 857 vm_offset_t frbp, hstp; 858 unsigned lnum; 859 scrshot_t *ptr = (scrshot_t *)data; 860 void *outp = ptr->buf; 861 862 s = spltty(); 863 if (ISGRAPHSC(scp)) { 864 splx(s); 865 return EOPNOTSUPP; 866 } 867 hist_rsz = (scp->history != NULL) ? scp->history->vtb_rows : 0; 868 if ((ptr->x + ptr->xsize) > scp->xsize || 869 (ptr->y + ptr->ysize) > (scp->ysize + hist_rsz)) { 870 splx(s); 871 return EINVAL; 872 } 873 874 lsize = scp->xsize * sizeof(u_int16_t); 875 csize = ptr->xsize * sizeof(u_int16_t); 876 /* Pointer to the last line of framebuffer */ 877 frbp = scp->vtb.vtb_buffer + scp->ysize * lsize + ptr->x * 878 sizeof(u_int16_t); 879 /* Pointer to the last line of target buffer */ 880 (vm_offset_t)outp += ptr->ysize * csize; 881 /* Pointer to the last line of history buffer */ 882 if (scp->history != NULL) 883 hstp = scp->history->vtb_buffer + sc_vtb_tail(scp->history) * 884 sizeof(u_int16_t) + ptr->x * sizeof(u_int16_t); 885 else 886 hstp = 0; 887 888 retval = 0; 889 for (lnum = 0; lnum < (ptr->y + ptr->ysize); lnum++) { 890 if (lnum < scp->ysize) { 891 frbp -= lsize; 892 } else { 893 hstp -= lsize; 894 if (hstp < scp->history->vtb_buffer) 895 hstp += scp->history->vtb_rows * lsize; 896 frbp = hstp; 897 } 898 if (lnum < ptr->y) 899 continue; 900 (vm_offset_t)outp -= csize; 901 retval = copyout((void *)frbp, outp, csize); 902 if (retval != 0) 903 break; 904 } 905 splx(s); 906 return retval; 907 } 908 909 case VT_SETMODE: /* set screen switcher mode */ 910 { 911 struct vt_mode *mode; 912 struct proc *p1; 913 914 mode = (struct vt_mode *)data; 915 DPRINTF(5, ("sc%d: VT_SETMODE ", sc->unit)); 916 if (scp->smode.mode == VT_PROCESS) { 917 p1 = pfind(scp->pid); 918 if (scp->proc == p1 && scp->proc != td->td_proc) { 919 if (p1) 920 PROC_UNLOCK(p1); 921 DPRINTF(5, ("error EPERM\n")); 922 return EPERM; 923 } 924 if (p1) 925 PROC_UNLOCK(p1); 926 } 927 s = spltty(); 928 if (mode->mode == VT_AUTO) { 929 scp->smode.mode = VT_AUTO; 930 scp->proc = NULL; 931 scp->pid = 0; 932 DPRINTF(5, ("VT_AUTO, ")); 933 if ((scp == sc->cur_scp) && (sc->unit == sc_console_unit)) 934 cnavailable(sc_consptr, TRUE); 935 /* were we in the middle of the vty switching process? */ 936 if (finish_vt_rel(scp, TRUE, &s) == 0) 937 DPRINTF(5, ("reset WAIT_REL, ")); 938 if (finish_vt_acq(scp) == 0) 939 DPRINTF(5, ("reset WAIT_ACQ, ")); 940 } else { 941 if (!ISSIGVALID(mode->relsig) || !ISSIGVALID(mode->acqsig) 942 || !ISSIGVALID(mode->frsig)) { 943 splx(s); 944 DPRINTF(5, ("error EINVAL\n")); 945 return EINVAL; 946 } 947 DPRINTF(5, ("VT_PROCESS %d, ", td->td_proc->p_pid)); 948 bcopy(data, &scp->smode, sizeof(struct vt_mode)); 949 scp->proc = td->td_proc; 950 scp->pid = scp->proc->p_pid; 951 if ((scp == sc->cur_scp) && (sc->unit == sc_console_unit)) 952 cnavailable(sc_consptr, FALSE); 953 } 954 splx(s); 955 DPRINTF(5, ("\n")); 956 return 0; 957 } 958 959 case VT_GETMODE: /* get screen switcher mode */ 960 bcopy(&scp->smode, data, sizeof(struct vt_mode)); 961 return 0; 962 963 case VT_RELDISP: /* screen switcher ioctl */ 964 s = spltty(); 965 /* 966 * This must be the current vty which is in the VT_PROCESS 967 * switching mode... 968 */ 969 if ((scp != sc->cur_scp) || (scp->smode.mode != VT_PROCESS)) { 970 splx(s); 971 return EINVAL; 972 } 973 /* ...and this process is controlling it. */ 974 if (scp->proc != td->td_proc) { 975 splx(s); 976 return EPERM; 977 } 978 error = EINVAL; 979 switch(*(intptr_t *)data) { 980 case VT_FALSE: /* user refuses to release screen, abort */ 981 if ((error = finish_vt_rel(scp, FALSE, &s)) == 0) 982 DPRINTF(5, ("sc%d: VT_FALSE\n", sc->unit)); 983 break; 984 case VT_TRUE: /* user has released screen, go on */ 985 if ((error = finish_vt_rel(scp, TRUE, &s)) == 0) 986 DPRINTF(5, ("sc%d: VT_TRUE\n", sc->unit)); 987 break; 988 case VT_ACKACQ: /* acquire acknowledged, switch completed */ 989 if ((error = finish_vt_acq(scp)) == 0) 990 DPRINTF(5, ("sc%d: VT_ACKACQ\n", sc->unit)); 991 break; 992 default: 993 break; 994 } 995 splx(s); 996 return error; 997 998 case VT_OPENQRY: /* return free virtual console */ 999 for (i = sc->first_vty; i < sc->first_vty + sc->vtys; i++) { 1000 tp = VIRTUAL_TTY(sc, i); 1001 if (!ISTTYOPEN(tp)) { 1002 *(int *)data = i + 1; 1003 return 0; 1004 } 1005 } 1006 return EINVAL; 1007 1008 case VT_ACTIVATE: /* switch to screen *data */ 1009 i = (*(intptr_t *)data == 0) ? scp->index : (*(intptr_t *)data - 1); 1010 s = spltty(); 1011 sc_clean_up(sc->cur_scp); 1012 splx(s); 1013 return sc_switch_scr(sc, i); 1014 1015 case VT_WAITACTIVE: /* wait for switch to occur */ 1016 i = (*(intptr_t *)data == 0) ? scp->index : (*(intptr_t *)data - 1); 1017 if ((i < sc->first_vty) || (i >= sc->first_vty + sc->vtys)) 1018 return EINVAL; 1019 s = spltty(); 1020 error = sc_clean_up(sc->cur_scp); 1021 splx(s); 1022 if (error) 1023 return error; 1024 scp = sc_get_stat(SC_DEV(sc, i)); 1025 if (scp == scp->sc->cur_scp) 1026 return 0; 1027 while ((error=tsleep(&scp->smode, PZERO|PCATCH, 1028 "waitvt", 0)) == ERESTART) ; 1029 return error; 1030 1031 case VT_GETACTIVE: /* get active vty # */ 1032 *(int *)data = sc->cur_scp->index + 1; 1033 return 0; 1034 1035 case VT_GETINDEX: /* get this vty # */ 1036 *(int *)data = scp->index + 1; 1037 return 0; 1038 1039 case VT_LOCKSWITCH: /* prevent vty switching */ 1040 if ((*(int *)data) & 0x01) 1041 sc->flags |= SC_SCRN_VTYLOCK; 1042 else 1043 sc->flags &= ~SC_SCRN_VTYLOCK; 1044 return 0; 1045 1046 case KDENABIO: /* allow io operations */ 1047 error = suser(td); 1048 if (error != 0) 1049 return error; 1050 error = securelevel_gt(td->td_ucred, 0); 1051 if (error != 0) 1052 return error; 1053#ifdef __i386__ 1054 td->td_frame->tf_eflags |= PSL_IOPL; 1055#endif 1056 return 0; 1057 1058 case KDDISABIO: /* disallow io operations (default) */ 1059#ifdef __i386__ 1060 td->td_frame->tf_eflags &= ~PSL_IOPL; 1061#endif 1062 return 0; 1063 1064 case KDSKBSTATE: /* set keyboard state (locks) */ 1065 if (*(int *)data & ~LOCK_MASK) 1066 return EINVAL; 1067 scp->status &= ~LOCK_MASK; 1068 scp->status |= *(int *)data; 1069 if (scp == sc->cur_scp) 1070 update_kbd_state(scp, scp->status, LOCK_MASK); 1071 return 0; 1072 1073 case KDGKBSTATE: /* get keyboard state (locks) */ 1074 if (scp == sc->cur_scp) 1075 save_kbd_state(scp); 1076 *(int *)data = scp->status & LOCK_MASK; 1077 return 0; 1078 1079 case KDGETREPEAT: /* get keyboard repeat & delay rates */ 1080 case KDSETREPEAT: /* set keyboard repeat & delay rates (new) */ 1081 error = kbd_ioctl(sc->kbd, cmd, data); 1082 if (error == ENOIOCTL) 1083 error = ENODEV; 1084 return error; 1085 1086 case KDSETRAD: /* set keyboard repeat & delay rates (old) */ 1087 if (*(int *)data & ~0x7f) 1088 return EINVAL; 1089 error = kbd_ioctl(sc->kbd, cmd, data); 1090 if (error == ENOIOCTL) 1091 error = ENODEV; 1092 return error; 1093 1094 case KDSKBMODE: /* set keyboard mode */ 1095 switch (*(int *)data) { 1096 case K_XLATE: /* switch to XLT ascii mode */ 1097 case K_RAW: /* switch to RAW scancode mode */ 1098 case K_CODE: /* switch to CODE mode */ 1099 scp->kbd_mode = *(int *)data; 1100 if (scp == sc->cur_scp) 1101 kbd_ioctl(sc->kbd, cmd, data); 1102 return 0; 1103 default: 1104 return EINVAL; 1105 } 1106 /* NOT REACHED */ 1107 1108 case KDGKBMODE: /* get keyboard mode */ 1109 *(int *)data = scp->kbd_mode; 1110 return 0; 1111 1112 case KDGKBINFO: 1113 error = kbd_ioctl(sc->kbd, cmd, data); 1114 if (error == ENOIOCTL) 1115 error = ENODEV; 1116 return error; 1117 1118 case KDMKTONE: /* sound the bell */ 1119 if (*(int*)data) 1120 sc_bell(scp, (*(int*)data)&0xffff, 1121 (((*(int*)data)>>16)&0xffff)*hz/1000); 1122 else 1123 sc_bell(scp, scp->bell_pitch, scp->bell_duration); 1124 return 0; 1125 1126 case KIOCSOUND: /* make tone (*data) hz */ 1127 if (scp == sc->cur_scp) { 1128 if (*(int *)data) 1129 return sc_tone(*(int *)data); 1130 else 1131 return sc_tone(0); 1132 } 1133 return 0; 1134 1135 case KDGKBTYPE: /* get keyboard type */ 1136 error = kbd_ioctl(sc->kbd, cmd, data); 1137 if (error == ENOIOCTL) { 1138 /* always return something? XXX */ 1139 *(int *)data = 0; 1140 } 1141 return 0; 1142 1143 case KDSETLED: /* set keyboard LED status */ 1144 if (*(int *)data & ~LED_MASK) /* FIXME: LOCK_MASK? */ 1145 return EINVAL; 1146 scp->status &= ~LED_MASK; 1147 scp->status |= *(int *)data; 1148 if (scp == sc->cur_scp) 1149 update_kbd_leds(scp, scp->status); 1150 return 0; 1151 1152 case KDGETLED: /* get keyboard LED status */ 1153 if (scp == sc->cur_scp) 1154 save_kbd_state(scp); 1155 *(int *)data = scp->status & LED_MASK; 1156 return 0; 1157 1158 case CONS_SETKBD: /* set the new keyboard */ 1159 { 1160 keyboard_t *newkbd; 1161 1162 s = spltty(); 1163 newkbd = kbd_get_keyboard(*(int *)data); 1164 if (newkbd == NULL) { 1165 splx(s); 1166 return EINVAL; 1167 } 1168 error = 0; 1169 if (sc->kbd != newkbd) { 1170 i = kbd_allocate(newkbd->kb_name, newkbd->kb_unit, 1171 (void *)&sc->keyboard, sckbdevent, sc); 1172 /* i == newkbd->kb_index */ 1173 if (i >= 0) { 1174 if (sc->kbd != NULL) { 1175 save_kbd_state(sc->cur_scp); 1176 kbd_release(sc->kbd, (void *)&sc->keyboard); 1177 } 1178 sc->kbd = kbd_get_keyboard(i); /* sc->kbd == newkbd */ 1179 sc->keyboard = i; 1180 kbd_ioctl(sc->kbd, KDSKBMODE, 1181 (caddr_t)&sc->cur_scp->kbd_mode); 1182 update_kbd_state(sc->cur_scp, sc->cur_scp->status, 1183 LOCK_MASK); 1184 } else { 1185 error = EPERM; /* XXX */ 1186 } 1187 } 1188 splx(s); 1189 return error; 1190 } 1191 1192 case CONS_RELKBD: /* release the current keyboard */ 1193 s = spltty(); 1194 error = 0; 1195 if (sc->kbd != NULL) { 1196 save_kbd_state(sc->cur_scp); 1197 error = kbd_release(sc->kbd, (void *)&sc->keyboard); 1198 if (error == 0) { 1199 sc->kbd = NULL; 1200 sc->keyboard = -1; 1201 } 1202 } 1203 splx(s); 1204 return error; 1205 1206 case CONS_GETTERM: /* get the current terminal emulator info */ 1207 { 1208 sc_term_sw_t *sw; 1209 1210 if (((term_info_t *)data)->ti_index == 0) { 1211 sw = scp->tsw; 1212 } else { 1213 sw = sc_term_match_by_number(((term_info_t *)data)->ti_index); 1214 } 1215 if (sw != NULL) { 1216 strncpy(((term_info_t *)data)->ti_name, sw->te_name, 1217 sizeof(((term_info_t *)data)->ti_name)); 1218 strncpy(((term_info_t *)data)->ti_desc, sw->te_desc, 1219 sizeof(((term_info_t *)data)->ti_desc)); 1220 ((term_info_t *)data)->ti_flags = 0; 1221 return 0; 1222 } else { 1223 ((term_info_t *)data)->ti_name[0] = '\0'; 1224 ((term_info_t *)data)->ti_desc[0] = '\0'; 1225 ((term_info_t *)data)->ti_flags = 0; 1226 return EINVAL; 1227 } 1228 } 1229 1230 case CONS_SETTERM: /* set the current terminal emulator */ 1231 s = spltty(); 1232 error = sc_init_emulator(scp, ((term_info_t *)data)->ti_name); 1233 /* FIXME: what if scp == sc_console! XXX */ 1234 splx(s); 1235 return error; 1236 1237 case GIO_SCRNMAP: /* get output translation table */ 1238 bcopy(&sc->scr_map, data, sizeof(sc->scr_map)); 1239 return 0; 1240 1241 case PIO_SCRNMAP: /* set output translation table */ 1242 bcopy(data, &sc->scr_map, sizeof(sc->scr_map)); 1243 for (i=0; i<sizeof(sc->scr_map); i++) { 1244 sc->scr_rmap[sc->scr_map[i]] = i; 1245 } 1246 return 0; 1247 1248 case GIO_KEYMAP: /* get keyboard translation table */ 1249 case PIO_KEYMAP: /* set keyboard translation table */ 1250 case GIO_DEADKEYMAP: /* get accent key translation table */ 1251 case PIO_DEADKEYMAP: /* set accent key translation table */ 1252 case GETFKEY: /* get function key string */ 1253 case SETFKEY: /* set function key string */ 1254 error = kbd_ioctl(sc->kbd, cmd, data); 1255 if (error == ENOIOCTL) 1256 error = ENODEV; 1257 return error; 1258 1259#ifndef SC_NO_FONT_LOADING 1260 1261 case PIO_FONT8x8: /* set 8x8 dot font */ 1262 if (!ISFONTAVAIL(sc->adp->va_flags)) 1263 return ENXIO; 1264 bcopy(data, sc->font_8, 8*256); 1265 sc->fonts_loaded |= FONT_8; 1266 /* 1267 * FONT KLUDGE 1268 * Always use the font page #0. XXX 1269 * Don't load if the current font size is not 8x8. 1270 */ 1271 if (ISTEXTSC(sc->cur_scp) && (sc->cur_scp->font_size < 14)) 1272 sc_load_font(sc->cur_scp, 0, 8, sc->font_8, 0, 256); 1273 return 0; 1274 1275 case GIO_FONT8x8: /* get 8x8 dot font */ 1276 if (!ISFONTAVAIL(sc->adp->va_flags)) 1277 return ENXIO; 1278 if (sc->fonts_loaded & FONT_8) { 1279 bcopy(sc->font_8, data, 8*256); 1280 return 0; 1281 } 1282 else 1283 return ENXIO; 1284 1285 case PIO_FONT8x14: /* set 8x14 dot font */ 1286 if (!ISFONTAVAIL(sc->adp->va_flags)) 1287 return ENXIO; 1288 bcopy(data, sc->font_14, 14*256); 1289 sc->fonts_loaded |= FONT_14; 1290 /* 1291 * FONT KLUDGE 1292 * Always use the font page #0. XXX 1293 * Don't load if the current font size is not 8x14. 1294 */ 1295 if (ISTEXTSC(sc->cur_scp) 1296 && (sc->cur_scp->font_size >= 14) 1297 && (sc->cur_scp->font_size < 16)) 1298 sc_load_font(sc->cur_scp, 0, 14, sc->font_14, 0, 256); 1299 return 0; 1300 1301 case GIO_FONT8x14: /* get 8x14 dot font */ 1302 if (!ISFONTAVAIL(sc->adp->va_flags)) 1303 return ENXIO; 1304 if (sc->fonts_loaded & FONT_14) { 1305 bcopy(sc->font_14, data, 14*256); 1306 return 0; 1307 } 1308 else 1309 return ENXIO; 1310 1311 case PIO_FONT8x16: /* set 8x16 dot font */ 1312 if (!ISFONTAVAIL(sc->adp->va_flags)) 1313 return ENXIO; 1314 bcopy(data, sc->font_16, 16*256); 1315 sc->fonts_loaded |= FONT_16; 1316 /* 1317 * FONT KLUDGE 1318 * Always use the font page #0. XXX 1319 * Don't load if the current font size is not 8x16. 1320 */ 1321 if (ISTEXTSC(sc->cur_scp) && (sc->cur_scp->font_size >= 16)) 1322 sc_load_font(sc->cur_scp, 0, 16, sc->font_16, 0, 256); 1323 return 0; 1324 1325 case GIO_FONT8x16: /* get 8x16 dot font */ 1326 if (!ISFONTAVAIL(sc->adp->va_flags)) 1327 return ENXIO; 1328 if (sc->fonts_loaded & FONT_16) { 1329 bcopy(sc->font_16, data, 16*256); 1330 return 0; 1331 } 1332 else 1333 return ENXIO; 1334 1335#endif /* SC_NO_FONT_LOADING */ 1336 1337#ifdef PC98 1338 case ADJUST_CLOCK: /* /dev/rtc for 98note resume */ 1339 inittodr(0); 1340 return 0; 1341#endif 1342 1343 default: 1344 break; 1345 } 1346 1347 return (ttyioctl(dev, cmd, data, flag, td)); 1348} 1349 1350static void 1351scstart(struct tty *tp) 1352{ 1353 struct clist *rbp; 1354 int s, len; 1355 u_char buf[PCBURST]; 1356 scr_stat *scp = sc_get_stat(tp->t_dev); 1357 1358 if (scp->status & SLKED || 1359 (scp == scp->sc->cur_scp && scp->sc->blink_in_progress)) 1360 return; 1361 s = spltty(); 1362 if (!(tp->t_state & (TS_TIMEOUT | TS_BUSY | TS_TTSTOP))) { 1363 tp->t_state |= TS_BUSY; 1364 rbp = &tp->t_outq; 1365 while (rbp->c_cc) { 1366 len = q_to_b(rbp, buf, PCBURST); 1367 splx(s); 1368 sc_puts(scp, buf, len); 1369 s = spltty(); 1370 } 1371 tp->t_state &= ~TS_BUSY; 1372 ttwwakeup(tp); 1373 } 1374 splx(s); 1375} 1376 1377static void 1378sccnprobe(struct consdev *cp) 1379{ 1380#if !__alpha__ 1381 int unit; 1382 int flags; 1383 1384 cp->cn_pri = sc_get_cons_priority(&unit, &flags); 1385 1386 /* a video card is always required */ 1387 if (!scvidprobe(unit, flags, TRUE)) 1388 cp->cn_pri = CN_DEAD; 1389 1390 /* syscons will become console even when there is no keyboard */ 1391 sckbdprobe(unit, flags, TRUE); 1392 1393 if (cp->cn_pri == CN_DEAD) 1394 return; 1395 1396 /* initialize required fields */ 1397 sprintf(cp->cn_name, "consolectl"); 1398#endif /* !__alpha__ */ 1399 1400#if __alpha__ 1401 /* 1402 * alpha use sccnattach() rather than cnprobe()/cninit()/cnterm() 1403 * interface to install the console. Always return CN_DEAD from 1404 * here. 1405 */ 1406 cp->cn_pri = CN_DEAD; 1407#endif /* __alpha__ */ 1408} 1409 1410static void 1411sccninit(struct consdev *cp) 1412{ 1413#if !__alpha__ 1414 int unit; 1415 int flags; 1416 1417 sc_get_cons_priority(&unit, &flags); 1418 scinit(unit, flags | SC_KERNEL_CONSOLE); 1419 sc_console_unit = unit; 1420 sc_console = sc_get_stat(sc_get_softc(unit, SC_KERNEL_CONSOLE)->dev[0]); 1421 sc_consptr = cp; 1422#endif /* !__alpha__ */ 1423 1424#if __alpha__ 1425 /* SHOULDN'T REACH HERE */ 1426#endif /* __alpha__ */ 1427} 1428 1429static void 1430sccnterm(struct consdev *cp) 1431{ 1432 /* we are not the kernel console any more, release everything */ 1433 1434 if (sc_console_unit < 0) 1435 return; /* shouldn't happen */ 1436 1437#if !__alpha__ 1438#if 0 /* XXX */ 1439 sc_clear_screen(sc_console); 1440 sccnupdate(sc_console); 1441#endif 1442 scterm(sc_console_unit, SC_KERNEL_CONSOLE); 1443 sc_console_unit = -1; 1444 sc_console = NULL; 1445#endif /* !__alpha__ */ 1446 1447#if __alpha__ 1448 /* do nothing XXX */ 1449#endif /* __alpha__ */ 1450} 1451 1452#ifdef __alpha__ 1453 1454void 1455sccnattach(void) 1456{ 1457 static struct consdev consdev; 1458 int unit; 1459 int flags; 1460 1461 bcopy(&sc_consdev, &consdev, sizeof(sc_consdev)); 1462 consdev.cn_pri = sc_get_cons_priority(&unit, &flags); 1463 1464 /* a video card is always required */ 1465 if (!scvidprobe(unit, flags, TRUE)) 1466 consdev.cn_pri = CN_DEAD; 1467 1468 /* alpha doesn't allow the console being without a keyboard... Why? */ 1469 if (!sckbdprobe(unit, flags, TRUE)) 1470 consdev.cn_pri = CN_DEAD; 1471 1472 if (consdev.cn_pri == CN_DEAD) 1473 return; 1474 1475 scinit(unit, flags | SC_KERNEL_CONSOLE); 1476 sc_console_unit = unit; 1477 sc_consptr = &consdev; 1478 sc_console = sc_get_stat(sc_get_softc(unit, SC_KERNEL_CONSOLE)->dev[0]); 1479 sprintf(consdev.cn_name, "ttyv%r", 0); 1480 cnadd(&consdev); 1481} 1482 1483#endif /* __alpha__ */ 1484 1485static void 1486sccnputc(struct consdev *cd, int c) 1487{ 1488 u_char buf[1]; 1489 scr_stat *scp = sc_console; 1490 void *save; 1491#ifndef SC_NO_HISTORY 1492 struct tty *tp; 1493#endif /* !SC_NO_HISTORY */ 1494 int s; 1495 1496 /* assert(sc_console != NULL) */ 1497 1498#ifndef SC_NO_HISTORY 1499 if (scp == scp->sc->cur_scp && scp->status & SLKED) { 1500 scp->status &= ~SLKED; 1501 update_kbd_state(scp, scp->status, SLKED); 1502 if (scp->status & BUFFER_SAVED) { 1503 if (!sc_hist_restore(scp)) 1504 sc_remove_cutmarking(scp); 1505 scp->status &= ~BUFFER_SAVED; 1506 scp->status |= CURSOR_ENABLED; 1507 sc_draw_cursor_image(scp); 1508 } 1509 tp = VIRTUAL_TTY(scp->sc, scp->index); 1510 if (ISTTYOPEN(tp)) 1511 scstart(tp); 1512 } 1513#endif /* !SC_NO_HISTORY */ 1514 1515 save = scp->ts; 1516 if (kernel_console_ts != NULL) 1517 scp->ts = kernel_console_ts; 1518 buf[0] = c; 1519 sc_puts(scp, buf, 1); 1520 scp->ts = save; 1521 1522 s = spltty(); /* block sckbdevent and scrn_timer */ 1523 sccnupdate(scp); 1524 splx(s); 1525} 1526 1527static int 1528sccngetc(struct consdev *cd) 1529{ 1530 return sccngetch(0); 1531} 1532 1533static int 1534sccncheckc(struct consdev *cd) 1535{ 1536 return sccngetch(SCGETC_NONBLOCK); 1537} 1538 1539static void 1540sccndbctl(struct consdev *cd, int on) 1541{ 1542 /* assert(sc_console_unit >= 0) */ 1543 /* try to switch to the kernel console screen */ 1544 if (on && debugger == 0) { 1545 /* 1546 * TRY to make sure the screen saver is stopped, 1547 * and the screen is updated before switching to 1548 * the vty0. 1549 */ 1550 scrn_timer(NULL); 1551 if (!cold 1552 && sc_console->sc->cur_scp->smode.mode == VT_AUTO 1553 && sc_console->smode.mode == VT_AUTO) { 1554 sc_console->sc->cur_scp->status |= MOUSE_HIDDEN; 1555 ++debugger; /* XXX */ 1556#ifdef DDB 1557 /* unlock vty switching */ 1558 sc_console->sc->flags &= ~SC_SCRN_VTYLOCK; 1559#endif 1560 sc_switch_scr(sc_console->sc, sc_console->index); 1561 --debugger; /* XXX */ 1562 } 1563 } 1564 if (on) 1565 ++debugger; 1566 else 1567 --debugger; 1568} 1569 1570static int 1571sccngetch(int flags) 1572{ 1573 static struct fkeytab fkey; 1574 static int fkeycp; 1575 scr_stat *scp; 1576 u_char *p; 1577 int cur_mode; 1578 int s = spltty(); /* block sckbdevent and scrn_timer while we poll */ 1579 int c; 1580 1581 /* assert(sc_console != NULL) */ 1582 1583 /* 1584 * Stop the screen saver and update the screen if necessary. 1585 * What if we have been running in the screen saver code... XXX 1586 */ 1587 sc_touch_scrn_saver(); 1588 scp = sc_console->sc->cur_scp; /* XXX */ 1589 sccnupdate(scp); 1590 1591 if (fkeycp < fkey.len) { 1592 splx(s); 1593 return fkey.str[fkeycp++]; 1594 } 1595 1596 if (scp->sc->kbd == NULL) { 1597 splx(s); 1598 return -1; 1599 } 1600 1601 /* 1602 * Make sure the keyboard is accessible even when the kbd device 1603 * driver is disabled. 1604 */ 1605 kbd_enable(scp->sc->kbd); 1606 1607 /* we shall always use the keyboard in the XLATE mode here */ 1608 cur_mode = scp->kbd_mode; 1609 scp->kbd_mode = K_XLATE; 1610 kbd_ioctl(scp->sc->kbd, KDSKBMODE, (caddr_t)&scp->kbd_mode); 1611 1612 kbd_poll(scp->sc->kbd, TRUE); 1613 c = scgetc(scp->sc, SCGETC_CN | flags); 1614 kbd_poll(scp->sc->kbd, FALSE); 1615 1616 scp->kbd_mode = cur_mode; 1617 kbd_ioctl(scp->sc->kbd, KDSKBMODE, (caddr_t)&scp->kbd_mode); 1618 kbd_disable(scp->sc->kbd); 1619 splx(s); 1620 1621 switch (KEYFLAGS(c)) { 1622 case 0: /* normal char */ 1623 return KEYCHAR(c); 1624 case FKEY: /* function key */ 1625 p = kbd_get_fkeystr(scp->sc->kbd, KEYCHAR(c), (size_t *)&fkeycp); 1626 fkey.len = fkeycp; 1627 if ((p != NULL) && (fkey.len > 0)) { 1628 bcopy(p, fkey.str, fkey.len); 1629 fkeycp = 1; 1630 return fkey.str[0]; 1631 } 1632 return c; /* XXX */ 1633 case NOKEY: 1634 case ERRKEY: 1635 default: 1636 return -1; 1637 } 1638 /* NOT REACHED */ 1639} 1640 1641static void 1642sccnupdate(scr_stat *scp) 1643{ 1644 /* this is a cut-down version of scrn_timer()... */ 1645 1646 if (scp->sc->font_loading_in_progress || scp->sc->videoio_in_progress) 1647 return; 1648 1649 if (debugger > 0 || panicstr || shutdown_in_progress) { 1650 sc_touch_scrn_saver(); 1651 } else if (scp != scp->sc->cur_scp) { 1652 return; 1653 } 1654 1655 if (!run_scrn_saver) 1656 scp->sc->flags &= ~SC_SCRN_IDLE; 1657#ifdef DEV_SPLASH 1658 if ((saver_mode != CONS_LKM_SAVER) || !(scp->sc->flags & SC_SCRN_IDLE)) 1659 if (scp->sc->flags & SC_SCRN_BLANKED) 1660 stop_scrn_saver(scp->sc, current_saver); 1661#endif 1662 1663 if (scp != scp->sc->cur_scp || scp->sc->blink_in_progress 1664 || scp->sc->switch_in_progress) 1665 return; 1666 /* 1667 * FIXME: unlike scrn_timer(), we call scrn_update() from here even 1668 * when write_in_progress is non-zero. XXX 1669 */ 1670 1671 if (!ISGRAPHSC(scp) && !(scp->sc->flags & SC_SCRN_BLANKED)) 1672 scrn_update(scp, TRUE); 1673} 1674 1675static void 1676scrn_timer(void *arg) 1677{ 1678#ifndef PC98 1679 static int kbd_interval = 0; 1680#endif 1681 struct timeval tv; 1682 sc_softc_t *sc; 1683 scr_stat *scp; 1684 int again; 1685 int s; 1686 1687 again = (arg != NULL); 1688 if (arg != NULL) 1689 sc = (sc_softc_t *)arg; 1690 else if (sc_console != NULL) 1691 sc = sc_console->sc; 1692 else 1693 return; 1694 1695 /* don't do anything when we are performing some I/O operations */ 1696 if (sc->font_loading_in_progress || sc->videoio_in_progress) { 1697 if (again) 1698 timeout(scrn_timer, sc, hz / 10); 1699 return; 1700 } 1701 s = spltty(); 1702 1703#ifndef PC98 1704 if ((sc->kbd == NULL) && (sc->config & SC_AUTODETECT_KBD)) { 1705 /* try to allocate a keyboard automatically */ 1706 if (++kbd_interval >= 25) { 1707 sc->keyboard = kbd_allocate("*", -1, (void *)&sc->keyboard, 1708 sckbdevent, sc); 1709 if (sc->keyboard >= 0) { 1710 sc->kbd = kbd_get_keyboard(sc->keyboard); 1711 kbd_ioctl(sc->kbd, KDSKBMODE, 1712 (caddr_t)&sc->cur_scp->kbd_mode); 1713 update_kbd_state(sc->cur_scp, sc->cur_scp->status, 1714 LOCK_MASK); 1715 } 1716 kbd_interval = 0; 1717 } 1718 } 1719#endif /* PC98 */ 1720 1721 /* find the vty to update */ 1722 scp = sc->cur_scp; 1723 1724 /* should we stop the screen saver? */ 1725 getmicrouptime(&tv); 1726 if (debugger > 0 || panicstr || shutdown_in_progress) 1727 sc_touch_scrn_saver(); 1728 if (run_scrn_saver) { 1729 if (tv.tv_sec > sc->scrn_time_stamp + scrn_blank_time) 1730 sc->flags |= SC_SCRN_IDLE; 1731 else 1732 sc->flags &= ~SC_SCRN_IDLE; 1733 } else { 1734 sc->scrn_time_stamp = tv.tv_sec; 1735 sc->flags &= ~SC_SCRN_IDLE; 1736 if (scrn_blank_time > 0) 1737 run_scrn_saver = TRUE; 1738 } 1739#ifdef DEV_SPLASH 1740 if ((saver_mode != CONS_LKM_SAVER) || !(sc->flags & SC_SCRN_IDLE)) 1741 if (sc->flags & SC_SCRN_BLANKED) 1742 stop_scrn_saver(sc, current_saver); 1743#endif 1744 1745 /* should we just return ? */ 1746 if (sc->blink_in_progress || sc->switch_in_progress 1747 || sc->write_in_progress) { 1748 if (again) 1749 timeout(scrn_timer, sc, hz / 10); 1750 splx(s); 1751 return; 1752 } 1753 1754 /* Update the screen */ 1755 scp = sc->cur_scp; /* cur_scp may have changed... */ 1756 if (!ISGRAPHSC(scp) && !(sc->flags & SC_SCRN_BLANKED)) 1757 scrn_update(scp, TRUE); 1758 1759#ifdef DEV_SPLASH 1760 /* should we activate the screen saver? */ 1761 if ((saver_mode == CONS_LKM_SAVER) && (sc->flags & SC_SCRN_IDLE)) 1762 if (!ISGRAPHSC(scp) || (sc->flags & SC_SCRN_BLANKED)) 1763 (*current_saver)(sc, TRUE); 1764#endif 1765 1766 if (again) 1767 timeout(scrn_timer, sc, hz / 25); 1768 splx(s); 1769} 1770 1771static int 1772and_region(int *s1, int *e1, int s2, int e2) 1773{ 1774 if (*e1 < s2 || e2 < *s1) 1775 return FALSE; 1776 *s1 = imax(*s1, s2); 1777 *e1 = imin(*e1, e2); 1778 return TRUE; 1779} 1780 1781static void 1782scrn_update(scr_stat *scp, int show_cursor) 1783{ 1784 int start; 1785 int end; 1786 int s; 1787 int e; 1788 1789 /* assert(scp == scp->sc->cur_scp) */ 1790 1791 ++scp->sc->videoio_in_progress; 1792 1793#ifndef SC_NO_CUTPASTE 1794 /* remove the previous mouse pointer image if necessary */ 1795 if (scp->status & MOUSE_VISIBLE) { 1796 s = scp->mouse_pos; 1797 e = scp->mouse_pos + scp->xsize + 1; 1798 if ((scp->status & (MOUSE_MOVED | MOUSE_HIDDEN)) 1799 || and_region(&s, &e, scp->start, scp->end) 1800 || ((scp->status & CURSOR_ENABLED) && 1801 (scp->cursor_pos != scp->cursor_oldpos) && 1802 (and_region(&s, &e, scp->cursor_pos, scp->cursor_pos) 1803 || and_region(&s, &e, scp->cursor_oldpos, scp->cursor_oldpos)))) { 1804 sc_remove_mouse_image(scp); 1805 if (scp->end >= scp->xsize*scp->ysize) 1806 scp->end = scp->xsize*scp->ysize - 1; 1807 } 1808 } 1809#endif /* !SC_NO_CUTPASTE */ 1810 1811#if 1 1812 /* debug: XXX */ 1813 if (scp->end >= scp->xsize*scp->ysize) { 1814 printf("scrn_update(): scp->end %d > size_of_screen!!\n", scp->end); 1815 scp->end = scp->xsize*scp->ysize - 1; 1816 } 1817 if (scp->start < 0) { 1818 printf("scrn_update(): scp->start %d < 0\n", scp->start); 1819 scp->start = 0; 1820 } 1821#endif 1822 1823 /* update screen image */ 1824 if (scp->start <= scp->end) { 1825 if (scp->mouse_cut_end >= 0) { 1826 /* there is a marked region for cut & paste */ 1827 if (scp->mouse_cut_start <= scp->mouse_cut_end) { 1828 start = scp->mouse_cut_start; 1829 end = scp->mouse_cut_end; 1830 } else { 1831 start = scp->mouse_cut_end; 1832 end = scp->mouse_cut_start - 1; 1833 } 1834 s = start; 1835 e = end; 1836 /* does the cut-mark region overlap with the update region? */ 1837 if (and_region(&s, &e, scp->start, scp->end)) { 1838 (*scp->rndr->draw)(scp, s, e - s + 1, TRUE); 1839 s = 0; 1840 e = start - 1; 1841 if (and_region(&s, &e, scp->start, scp->end)) 1842 (*scp->rndr->draw)(scp, s, e - s + 1, FALSE); 1843 s = end + 1; 1844 e = scp->xsize*scp->ysize - 1; 1845 if (and_region(&s, &e, scp->start, scp->end)) 1846 (*scp->rndr->draw)(scp, s, e - s + 1, FALSE); 1847 } else { 1848 (*scp->rndr->draw)(scp, scp->start, 1849 scp->end - scp->start + 1, FALSE); 1850 } 1851 } else { 1852 (*scp->rndr->draw)(scp, scp->start, 1853 scp->end - scp->start + 1, FALSE); 1854 } 1855 } 1856 1857 /* we are not to show the cursor and the mouse pointer... */ 1858 if (!show_cursor) { 1859 scp->end = 0; 1860 scp->start = scp->xsize*scp->ysize - 1; 1861 --scp->sc->videoio_in_progress; 1862 return; 1863 } 1864 1865 /* update cursor image */ 1866 if (scp->status & CURSOR_ENABLED) { 1867 s = scp->start; 1868 e = scp->end; 1869 /* did cursor move since last time ? */ 1870 if (scp->cursor_pos != scp->cursor_oldpos) { 1871 /* do we need to remove old cursor image ? */ 1872 if (!and_region(&s, &e, scp->cursor_oldpos, scp->cursor_oldpos)) 1873 sc_remove_cursor_image(scp); 1874 sc_draw_cursor_image(scp); 1875 } else { 1876 if (and_region(&s, &e, scp->cursor_pos, scp->cursor_pos)) 1877 /* cursor didn't move, but has been overwritten */ 1878 sc_draw_cursor_image(scp); 1879 else if (scp->curs_attr.flags & CONS_BLINK_CURSOR) 1880 /* if it's a blinking cursor, update it */ 1881 (*scp->rndr->blink_cursor)(scp, scp->cursor_pos, 1882 sc_inside_cutmark(scp, 1883 scp->cursor_pos)); 1884 } 1885 } 1886 1887#ifndef SC_NO_CUTPASTE 1888 /* update "pseudo" mouse pointer image */ 1889 if (scp->sc->flags & SC_MOUSE_ENABLED) { 1890 if (!(scp->status & (MOUSE_VISIBLE | MOUSE_HIDDEN))) { 1891 scp->status &= ~MOUSE_MOVED; 1892 sc_draw_mouse_image(scp); 1893 } 1894 } 1895#endif /* SC_NO_CUTPASTE */ 1896 1897 scp->end = 0; 1898 scp->start = scp->xsize*scp->ysize - 1; 1899 1900 --scp->sc->videoio_in_progress; 1901} 1902 1903#ifdef DEV_SPLASH 1904static int 1905scsplash_callback(int event, void *arg) 1906{ 1907 sc_softc_t *sc; 1908 int error; 1909 1910 sc = (sc_softc_t *)arg; 1911 1912 switch (event) { 1913 case SPLASH_INIT: 1914 if (add_scrn_saver(scsplash_saver) == 0) { 1915 sc->flags &= ~SC_SAVER_FAILED; 1916 run_scrn_saver = TRUE; 1917 if (cold && !(boothowto & (RB_VERBOSE | RB_CONFIG))) { 1918 scsplash_stick(TRUE); 1919 (*current_saver)(sc, TRUE); 1920 } 1921 } 1922 return 0; 1923 1924 case SPLASH_TERM: 1925 if (current_saver == scsplash_saver) { 1926 scsplash_stick(FALSE); 1927 error = remove_scrn_saver(scsplash_saver); 1928 if (error) 1929 return error; 1930 } 1931 return 0; 1932 1933 default: 1934 return EINVAL; 1935 } 1936} 1937 1938static void 1939scsplash_saver(sc_softc_t *sc, int show) 1940{ 1941 static int busy = FALSE; 1942 scr_stat *scp; 1943 1944 if (busy) 1945 return; 1946 busy = TRUE; 1947 1948 scp = sc->cur_scp; 1949 if (show) { 1950 if (!(sc->flags & SC_SAVER_FAILED)) { 1951 if (!(sc->flags & SC_SCRN_BLANKED)) 1952 set_scrn_saver_mode(scp, -1, NULL, 0); 1953 switch (splash(sc->adp, TRUE)) { 1954 case 0: /* succeeded */ 1955 break; 1956 case EAGAIN: /* try later */ 1957 restore_scrn_saver_mode(scp, FALSE); 1958 sc_touch_scrn_saver(); /* XXX */ 1959 break; 1960 default: 1961 sc->flags |= SC_SAVER_FAILED; 1962 scsplash_stick(FALSE); 1963 restore_scrn_saver_mode(scp, TRUE); 1964 printf("scsplash_saver(): failed to put up the image\n"); 1965 break; 1966 } 1967 } 1968 } else if (!sticky_splash) { 1969 if ((sc->flags & SC_SCRN_BLANKED) && (splash(sc->adp, FALSE) == 0)) 1970 restore_scrn_saver_mode(scp, TRUE); 1971 } 1972 busy = FALSE; 1973} 1974 1975static int 1976add_scrn_saver(void (*this_saver)(sc_softc_t *, int)) 1977{ 1978#if 0 1979 int error; 1980 1981 if (current_saver != none_saver) { 1982 error = remove_scrn_saver(current_saver); 1983 if (error) 1984 return error; 1985 } 1986#endif 1987 if (current_saver != none_saver) 1988 return EBUSY; 1989 1990 run_scrn_saver = FALSE; 1991 saver_mode = CONS_LKM_SAVER; 1992 current_saver = this_saver; 1993 return 0; 1994} 1995 1996static int 1997remove_scrn_saver(void (*this_saver)(sc_softc_t *, int)) 1998{ 1999 if (current_saver != this_saver) 2000 return EINVAL; 2001 2002#if 0 2003 /* 2004 * In order to prevent `current_saver' from being called by 2005 * the timeout routine `scrn_timer()' while we manipulate 2006 * the saver list, we shall set `current_saver' to `none_saver' 2007 * before stopping the current saver, rather than blocking by `splXX()'. 2008 */ 2009 current_saver = none_saver; 2010 if (scrn_blanked) 2011 stop_scrn_saver(this_saver); 2012#endif 2013 2014 /* unblank all blanked screens */ 2015 wait_scrn_saver_stop(NULL); 2016 if (scrn_blanked) 2017 return EBUSY; 2018 2019 current_saver = none_saver; 2020 return 0; 2021} 2022 2023static int 2024set_scrn_saver_mode(scr_stat *scp, int mode, u_char *pal, int border) 2025{ 2026 int s; 2027 2028 /* assert(scp == scp->sc->cur_scp) */ 2029 s = spltty(); 2030 if (!ISGRAPHSC(scp)) 2031 sc_remove_cursor_image(scp); 2032 scp->splash_save_mode = scp->mode; 2033 scp->splash_save_status = scp->status & (GRAPHICS_MODE | PIXEL_MODE); 2034 scp->status &= ~(GRAPHICS_MODE | PIXEL_MODE); 2035 scp->status |= (UNKNOWN_MODE | SAVER_RUNNING); 2036 scp->sc->flags |= SC_SCRN_BLANKED; 2037 ++scrn_blanked; 2038 splx(s); 2039 if (mode < 0) 2040 return 0; 2041 scp->mode = mode; 2042 if (set_mode(scp) == 0) { 2043 if (scp->sc->adp->va_info.vi_flags & V_INFO_GRAPHICS) 2044 scp->status |= GRAPHICS_MODE; 2045#ifndef SC_NO_PALETTE_LOADING 2046 if (pal != NULL) 2047 load_palette(scp->sc->adp, pal); 2048#endif 2049 sc_set_border(scp, border); 2050 return 0; 2051 } else { 2052 s = spltty(); 2053 scp->mode = scp->splash_save_mode; 2054 scp->status &= ~(UNKNOWN_MODE | SAVER_RUNNING); 2055 scp->status |= scp->splash_save_status; 2056 splx(s); 2057 return 1; 2058 } 2059} 2060 2061static int 2062restore_scrn_saver_mode(scr_stat *scp, int changemode) 2063{ 2064 int mode; 2065 int status; 2066 int s; 2067 2068 /* assert(scp == scp->sc->cur_scp) */ 2069 s = spltty(); 2070 mode = scp->mode; 2071 status = scp->status; 2072 scp->mode = scp->splash_save_mode; 2073 scp->status &= ~(UNKNOWN_MODE | SAVER_RUNNING); 2074 scp->status |= scp->splash_save_status; 2075 scp->sc->flags &= ~SC_SCRN_BLANKED; 2076 if (!changemode) { 2077 if (!ISGRAPHSC(scp)) 2078 sc_draw_cursor_image(scp); 2079 --scrn_blanked; 2080 splx(s); 2081 return 0; 2082 } 2083 if (set_mode(scp) == 0) { 2084#ifndef SC_NO_PALETTE_LOADING 2085 load_palette(scp->sc->adp, scp->sc->palette); 2086#endif 2087 --scrn_blanked; 2088 splx(s); 2089 return 0; 2090 } else { 2091 scp->mode = mode; 2092 scp->status = status; 2093 splx(s); 2094 return 1; 2095 } 2096} 2097 2098static void 2099stop_scrn_saver(sc_softc_t *sc, void (*saver)(sc_softc_t *, int)) 2100{ 2101 (*saver)(sc, FALSE); 2102 run_scrn_saver = FALSE; 2103 /* the screen saver may have chosen not to stop after all... */ 2104 if (sc->flags & SC_SCRN_BLANKED) 2105 return; 2106 2107 mark_all(sc->cur_scp); 2108 if (sc->delayed_next_scr) 2109 sc_switch_scr(sc, sc->delayed_next_scr - 1); 2110 if (debugger == 0) 2111 wakeup(&scrn_blanked); 2112} 2113 2114static int 2115wait_scrn_saver_stop(sc_softc_t *sc) 2116{ 2117 int error = 0; 2118 2119 while (scrn_blanked > 0) { 2120 run_scrn_saver = FALSE; 2121 if (sc && !(sc->flags & SC_SCRN_BLANKED)) { 2122 error = 0; 2123 break; 2124 } 2125 error = tsleep(&scrn_blanked, PZERO | PCATCH, "scrsav", 0); 2126 if ((error != 0) && (error != ERESTART)) 2127 break; 2128 } 2129 run_scrn_saver = FALSE; 2130 return error; 2131} 2132#endif /* DEV_SPLASH */ 2133 2134void 2135sc_touch_scrn_saver(void) 2136{ 2137 scsplash_stick(FALSE); 2138 run_scrn_saver = FALSE; 2139} 2140 2141int 2142sc_switch_scr(sc_softc_t *sc, u_int next_scr) 2143{ 2144 scr_stat *cur_scp; 2145 struct tty *tp; 2146 struct proc *p; 2147 int s; 2148 2149 DPRINTF(5, ("sc0: sc_switch_scr() %d ", next_scr + 1)); 2150 2151 if (sc->cur_scp == NULL) 2152 return (0); 2153 2154 /* prevent switch if previously requested */ 2155 if (sc->flags & SC_SCRN_VTYLOCK) { 2156 sc_bell(sc->cur_scp, sc->cur_scp->bell_pitch, 2157 sc->cur_scp->bell_duration); 2158 return EPERM; 2159 } 2160 2161 /* delay switch if the screen is blanked or being updated */ 2162 if ((sc->flags & SC_SCRN_BLANKED) || sc->write_in_progress 2163 || sc->blink_in_progress || sc->videoio_in_progress) { 2164 sc->delayed_next_scr = next_scr + 1; 2165 sc_touch_scrn_saver(); 2166 DPRINTF(5, ("switch delayed\n")); 2167 return 0; 2168 } 2169 2170 s = spltty(); 2171 cur_scp = sc->cur_scp; 2172 2173 /* we are in the middle of the vty switching process... */ 2174 if (sc->switch_in_progress 2175 && (cur_scp->smode.mode == VT_PROCESS) 2176 && cur_scp->proc) { 2177 p = pfind(cur_scp->pid); 2178 if (cur_scp->proc != p) { 2179 if (p) 2180 PROC_UNLOCK(p); 2181 /* 2182 * The controlling process has died!!. Do some clean up. 2183 * NOTE:`cur_scp->proc' and `cur_scp->smode.mode' 2184 * are not reset here yet; they will be cleared later. 2185 */ 2186 DPRINTF(5, ("cur_scp controlling process %d died, ", 2187 cur_scp->pid)); 2188 if (cur_scp->status & SWITCH_WAIT_REL) { 2189 /* 2190 * Force the previous switch to finish, but return now 2191 * with error. 2192 */ 2193 DPRINTF(5, ("reset WAIT_REL, ")); 2194 finish_vt_rel(cur_scp, TRUE, &s); 2195 splx(s); 2196 DPRINTF(5, ("finishing previous switch\n")); 2197 return EINVAL; 2198 } else if (cur_scp->status & SWITCH_WAIT_ACQ) { 2199 /* let's assume screen switch has been completed. */ 2200 DPRINTF(5, ("reset WAIT_ACQ, ")); 2201 finish_vt_acq(cur_scp); 2202 } else { 2203 /* 2204 * We are in between screen release and acquisition, and 2205 * reached here via scgetc() or scrn_timer() which has 2206 * interrupted exchange_scr(). Don't do anything stupid. 2207 */ 2208 DPRINTF(5, ("waiting nothing, ")); 2209 } 2210 } else { 2211 if (p) 2212 PROC_UNLOCK(p); 2213 /* 2214 * The controlling process is alive, but not responding... 2215 * It is either buggy or it may be just taking time. 2216 * The following code is a gross kludge to cope with this 2217 * problem for which there is no clean solution. XXX 2218 */ 2219 if (cur_scp->status & SWITCH_WAIT_REL) { 2220 switch (sc->switch_in_progress++) { 2221 case 1: 2222 break; 2223 case 2: 2224 DPRINTF(5, ("sending relsig again, ")); 2225 signal_vt_rel(cur_scp); 2226 break; 2227 case 3: 2228 break; 2229 case 4: 2230 default: 2231 /* 2232 * Act as if the controlling program returned 2233 * VT_FALSE. 2234 */ 2235 DPRINTF(5, ("force reset WAIT_REL, ")); 2236 finish_vt_rel(cur_scp, FALSE, &s); 2237 splx(s); 2238 DPRINTF(5, ("act as if VT_FALSE was seen\n")); 2239 return EINVAL; 2240 } 2241 } else if (cur_scp->status & SWITCH_WAIT_ACQ) { 2242 switch (sc->switch_in_progress++) { 2243 case 1: 2244 break; 2245 case 2: 2246 DPRINTF(5, ("sending acqsig again, ")); 2247 signal_vt_acq(cur_scp); 2248 break; 2249 case 3: 2250 break; 2251 case 4: 2252 default: 2253 /* clear the flag and finish the previous switch */ 2254 DPRINTF(5, ("force reset WAIT_ACQ, ")); 2255 finish_vt_acq(cur_scp); 2256 break; 2257 } 2258 } 2259 } 2260 } 2261 2262 /* 2263 * Return error if an invalid argument is given, or vty switch 2264 * is still in progress. 2265 */ 2266 if ((next_scr < sc->first_vty) || (next_scr >= sc->first_vty + sc->vtys) 2267 || sc->switch_in_progress) { 2268 splx(s); 2269 sc_bell(cur_scp, bios_value.bell_pitch, BELL_DURATION); 2270 DPRINTF(5, ("error 1\n")); 2271 return EINVAL; 2272 } 2273 2274 /* 2275 * Don't allow switching away from the graphics mode vty 2276 * if the switch mode is VT_AUTO, unless the next vty is the same 2277 * as the current or the current vty has been closed (but showing). 2278 */ 2279 tp = VIRTUAL_TTY(sc, cur_scp->index); 2280 if ((cur_scp->index != next_scr) 2281 && ISTTYOPEN(tp) 2282 && (cur_scp->smode.mode == VT_AUTO) 2283 && ISGRAPHSC(cur_scp)) { 2284 splx(s); 2285 sc_bell(cur_scp, bios_value.bell_pitch, BELL_DURATION); 2286 DPRINTF(5, ("error, graphics mode\n")); 2287 return EINVAL; 2288 } 2289 2290 /* 2291 * Is the wanted vty open? Don't allow switching to a closed vty. 2292 * If we are in DDB, don't switch to a vty in the VT_PROCESS mode. 2293 * Note that we always allow the user to switch to the kernel 2294 * console even if it is closed. 2295 */ 2296 if ((sc_console == NULL) || (next_scr != sc_console->index)) { 2297 tp = VIRTUAL_TTY(sc, next_scr); 2298 if (!ISTTYOPEN(tp)) { 2299 splx(s); 2300 sc_bell(cur_scp, bios_value.bell_pitch, BELL_DURATION); 2301 DPRINTF(5, ("error 2, requested vty isn't open!\n")); 2302 return EINVAL; 2303 } 2304 if ((debugger > 0) && (SC_STAT(tp->t_dev)->smode.mode == VT_PROCESS)) { 2305 splx(s); 2306 DPRINTF(5, ("error 3, requested vty is in the VT_PROCESS mode\n")); 2307 return EINVAL; 2308 } 2309 } 2310 2311 /* this is the start of vty switching process... */ 2312 ++sc->switch_in_progress; 2313 sc->delayed_next_scr = 0; 2314 sc->old_scp = cur_scp; 2315 sc->new_scp = sc_get_stat(SC_DEV(sc, next_scr)); 2316 if (sc->new_scp == sc->old_scp) { 2317 sc->switch_in_progress = 0; 2318 /* 2319 * XXX wakeup() calls mtx_lock(&sched_lock) which will hang if 2320 * sched_lock is in an in-between state, e.g., when we stop at 2321 * a breakpoint at fork_exit. It has always been wrong to call 2322 * wakeup() when the debugger is active. In RELENG_4, wakeup() 2323 * is supposed to be locked by splhigh(), but the debugger may 2324 * be invoked at splhigh(). 2325 */ 2326 if (debugger == 0) 2327 wakeup(&sc->new_scp->smode); 2328 splx(s); 2329 DPRINTF(5, ("switch done (new == old)\n")); 2330 return 0; 2331 } 2332 2333 /* has controlling process died? */ 2334 vt_proc_alive(sc->old_scp); 2335 vt_proc_alive(sc->new_scp); 2336 2337 /* wait for the controlling process to release the screen, if necessary */ 2338 if (signal_vt_rel(sc->old_scp)) { 2339 splx(s); 2340 return 0; 2341 } 2342 2343 /* go set up the new vty screen */ 2344 splx(s); 2345 exchange_scr(sc); 2346 s = spltty(); 2347 2348 /* wake up processes waiting for this vty */ 2349 if (debugger == 0) 2350 wakeup(&sc->cur_scp->smode); 2351 2352 /* wait for the controlling process to acknowledge, if necessary */ 2353 if (signal_vt_acq(sc->cur_scp)) { 2354 splx(s); 2355 return 0; 2356 } 2357 2358 sc->switch_in_progress = 0; 2359 if (sc->unit == sc_console_unit) 2360 cnavailable(sc_consptr, TRUE); 2361 splx(s); 2362 DPRINTF(5, ("switch done\n")); 2363 2364 return 0; 2365} 2366 2367static int 2368do_switch_scr(sc_softc_t *sc, int s) 2369{ 2370 vt_proc_alive(sc->new_scp); 2371 2372 splx(s); 2373 exchange_scr(sc); 2374 s = spltty(); 2375 /* sc->cur_scp == sc->new_scp */ 2376 wakeup(&sc->cur_scp->smode); 2377 2378 /* wait for the controlling process to acknowledge, if necessary */ 2379 if (!signal_vt_acq(sc->cur_scp)) { 2380 sc->switch_in_progress = 0; 2381 if (sc->unit == sc_console_unit) 2382 cnavailable(sc_consptr, TRUE); 2383 } 2384 2385 return s; 2386} 2387 2388static int 2389vt_proc_alive(scr_stat *scp) 2390{ 2391 struct proc *p; 2392 2393 if (scp->proc) { 2394 if ((p = pfind(scp->pid)) != NULL) 2395 PROC_UNLOCK(p); 2396 if (scp->proc == p) 2397 return TRUE; 2398 scp->proc = NULL; 2399 scp->smode.mode = VT_AUTO; 2400 DPRINTF(5, ("vt controlling process %d died\n", scp->pid)); 2401 } 2402 return FALSE; 2403} 2404 2405static int 2406signal_vt_rel(scr_stat *scp) 2407{ 2408 if (scp->smode.mode != VT_PROCESS) 2409 return FALSE; 2410 scp->status |= SWITCH_WAIT_REL; 2411 PROC_LOCK(scp->proc); 2412 psignal(scp->proc, scp->smode.relsig); 2413 PROC_UNLOCK(scp->proc); 2414 DPRINTF(5, ("sending relsig to %d\n", scp->pid)); 2415 return TRUE; 2416} 2417 2418static int 2419signal_vt_acq(scr_stat *scp) 2420{ 2421 if (scp->smode.mode != VT_PROCESS) 2422 return FALSE; 2423 if (scp->sc->unit == sc_console_unit) 2424 cnavailable(sc_consptr, FALSE); 2425 scp->status |= SWITCH_WAIT_ACQ; 2426 PROC_LOCK(scp->proc); 2427 psignal(scp->proc, scp->smode.acqsig); 2428 PROC_UNLOCK(scp->proc); 2429 DPRINTF(5, ("sending acqsig to %d\n", scp->pid)); 2430 return TRUE; 2431} 2432 2433static int 2434finish_vt_rel(scr_stat *scp, int release, int *s) 2435{ 2436 if (scp == scp->sc->old_scp && scp->status & SWITCH_WAIT_REL) { 2437 scp->status &= ~SWITCH_WAIT_REL; 2438 if (release) 2439 *s = do_switch_scr(scp->sc, *s); 2440 else 2441 scp->sc->switch_in_progress = 0; 2442 return 0; 2443 } 2444 return EINVAL; 2445} 2446 2447static int 2448finish_vt_acq(scr_stat *scp) 2449{ 2450 if (scp == scp->sc->new_scp && scp->status & SWITCH_WAIT_ACQ) { 2451 scp->status &= ~SWITCH_WAIT_ACQ; 2452 scp->sc->switch_in_progress = 0; 2453 return 0; 2454 } 2455 return EINVAL; 2456} 2457 2458static void 2459exchange_scr(sc_softc_t *sc) 2460{ 2461 scr_stat *scp; 2462 2463 /* save the current state of video and keyboard */ 2464 sc_move_cursor(sc->old_scp, sc->old_scp->xpos, sc->old_scp->ypos); 2465 if (!ISGRAPHSC(sc->old_scp)) 2466 sc_remove_cursor_image(sc->old_scp); 2467 if (sc->old_scp->kbd_mode == K_XLATE) 2468 save_kbd_state(sc->old_scp); 2469 2470 /* set up the video for the new screen */ 2471 scp = sc->cur_scp = sc->new_scp; 2472#ifdef PC98 2473 if (sc->old_scp->mode != scp->mode || ISUNKNOWNSC(sc->old_scp) || ISUNKNOWNSC(sc->new_scp)) 2474#else 2475 if (sc->old_scp->mode != scp->mode || ISUNKNOWNSC(sc->old_scp)) 2476#endif 2477 set_mode(scp); 2478#ifndef __sparc64__ 2479 else 2480 sc_vtb_init(&scp->scr, VTB_FRAMEBUFFER, scp->xsize, scp->ysize, 2481 (void *)sc->adp->va_window, FALSE); 2482#endif 2483 scp->status |= MOUSE_HIDDEN; 2484 sc_move_cursor(scp, scp->xpos, scp->ypos); 2485 if (!ISGRAPHSC(scp)) 2486 sc_set_cursor_image(scp); 2487#ifndef SC_NO_PALETTE_LOADING 2488 if (ISGRAPHSC(sc->old_scp)) 2489 load_palette(sc->adp, sc->palette); 2490#endif 2491 sc_set_border(scp, scp->border); 2492 2493 /* set up the keyboard for the new screen */ 2494 if (sc->old_scp->kbd_mode != scp->kbd_mode) 2495 kbd_ioctl(sc->kbd, KDSKBMODE, (caddr_t)&scp->kbd_mode); 2496 update_kbd_state(scp, scp->status, LOCK_MASK); 2497 2498 mark_all(scp); 2499} 2500 2501void 2502sc_puts(scr_stat *scp, u_char *buf, int len) 2503{ 2504#ifdef DEV_SPLASH 2505 /* make screensaver happy */ 2506 if (!sticky_splash && scp == scp->sc->cur_scp && !sc_saver_keyb_only) 2507 run_scrn_saver = FALSE; 2508#endif 2509 2510 if (scp->tsw) 2511 (*scp->tsw->te_puts)(scp, buf, len); 2512 2513 if (scp->sc->delayed_next_scr) 2514 sc_switch_scr(scp->sc, scp->sc->delayed_next_scr - 1); 2515} 2516 2517void 2518sc_draw_cursor_image(scr_stat *scp) 2519{ 2520 /* assert(scp == scp->sc->cur_scp); */ 2521 ++scp->sc->videoio_in_progress; 2522 (*scp->rndr->draw_cursor)(scp, scp->cursor_pos, 2523 scp->curs_attr.flags & CONS_BLINK_CURSOR, TRUE, 2524 sc_inside_cutmark(scp, scp->cursor_pos)); 2525 scp->cursor_oldpos = scp->cursor_pos; 2526 --scp->sc->videoio_in_progress; 2527} 2528 2529void 2530sc_remove_cursor_image(scr_stat *scp) 2531{ 2532 /* assert(scp == scp->sc->cur_scp); */ 2533 ++scp->sc->videoio_in_progress; 2534 (*scp->rndr->draw_cursor)(scp, scp->cursor_oldpos, 2535 scp->curs_attr.flags & CONS_BLINK_CURSOR, FALSE, 2536 sc_inside_cutmark(scp, scp->cursor_oldpos)); 2537 --scp->sc->videoio_in_progress; 2538} 2539 2540static void 2541update_cursor_image(scr_stat *scp) 2542{ 2543 /* assert(scp == scp->sc->cur_scp); */ 2544 sc_remove_cursor_image(scp); 2545 sc_set_cursor_image(scp); 2546 sc_draw_cursor_image(scp); 2547} 2548 2549void 2550sc_set_cursor_image(scr_stat *scp) 2551{ 2552 scp->curs_attr.flags = scp->curr_curs_attr.flags; 2553 if (scp->curs_attr.flags & CONS_HIDDEN_CURSOR) { 2554 /* hidden cursor is internally represented as zero-height underline */ 2555 scp->curs_attr.flags = CONS_CHAR_CURSOR; 2556 scp->curs_attr.base = scp->curs_attr.height = 0; 2557 } else if (scp->curs_attr.flags & CONS_CHAR_CURSOR) { 2558 scp->curs_attr.base = imin(scp->curr_curs_attr.base, 2559 scp->font_size - 1); 2560 scp->curs_attr.height = imin(scp->curr_curs_attr.height, 2561 scp->font_size - scp->curs_attr.base); 2562 } else { /* block cursor */ 2563 scp->curs_attr.base = 0; 2564 scp->curs_attr.height = scp->font_size; 2565 } 2566 2567 /* assert(scp == scp->sc->cur_scp); */ 2568 ++scp->sc->videoio_in_progress; 2569 (*scp->rndr->set_cursor)(scp, scp->curs_attr.base, scp->curs_attr.height, 2570 scp->curs_attr.flags & CONS_BLINK_CURSOR); 2571 --scp->sc->videoio_in_progress; 2572} 2573 2574static void 2575change_cursor_shape(scr_stat *scp, int flags, int base, int height) 2576{ 2577 if ((scp == scp->sc->cur_scp) && !ISGRAPHSC(scp)) 2578 sc_remove_cursor_image(scp); 2579 2580 if (base >= 0) 2581 scp->curr_curs_attr.base = base; 2582 if (height >= 0) 2583 scp->curr_curs_attr.height = height; 2584 if (flags & CONS_RESET_CURSOR) 2585 scp->curr_curs_attr = scp->dflt_curs_attr; 2586 else 2587 scp->curr_curs_attr.flags = flags & CONS_CURSOR_ATTRS; 2588 2589 if ((scp == scp->sc->cur_scp) && !ISGRAPHSC(scp)) { 2590 sc_set_cursor_image(scp); 2591 sc_draw_cursor_image(scp); 2592 } 2593} 2594 2595void 2596sc_change_cursor_shape(scr_stat *scp, int flags, int base, int height) 2597{ 2598 sc_softc_t *sc; 2599 struct cdev *dev; 2600 int s; 2601 int i; 2602 2603 s = spltty(); 2604 if ((flags != -1) && (flags & CONS_LOCAL_CURSOR)) { 2605 /* local (per vty) change */ 2606 change_cursor_shape(scp, flags, base, height); 2607 splx(s); 2608 return; 2609 } 2610 2611 /* global change */ 2612 sc = scp->sc; 2613 if (base >= 0) 2614 sc->curs_attr.base = base; 2615 if (height >= 0) 2616 sc->curs_attr.height = height; 2617 if (flags != -1) { 2618 if (flags & CONS_RESET_CURSOR) 2619 sc->curs_attr = sc->dflt_curs_attr; 2620 else 2621 sc->curs_attr.flags = flags & CONS_CURSOR_ATTRS; 2622 } 2623 2624 for (i = sc->first_vty; i < sc->first_vty + sc->vtys; ++i) {
|
2626 continue; 2627 if ((scp = sc_get_stat(dev)) == NULL) 2628 continue; 2629 scp->dflt_curs_attr = sc->curs_attr; 2630 change_cursor_shape(scp, CONS_RESET_CURSOR, -1, -1); 2631 } 2632 splx(s); 2633} 2634 2635static void 2636scinit(int unit, int flags) 2637{ 2638 /* 2639 * When syscons is being initialized as the kernel console, malloc() 2640 * is not yet functional, because various kernel structures has not been 2641 * fully initialized yet. Therefore, we need to declare the following 2642 * static buffers for the console. This is less than ideal, 2643 * but is necessry evil for the time being. XXX 2644 */ 2645#ifdef PC98 2646 static u_short sc_buffer[ROW*COL*2];/* XXX */ 2647#else 2648 static u_short sc_buffer[ROW*COL]; /* XXX */ 2649#endif 2650#ifndef SC_NO_FONT_LOADING 2651 static u_char font_8[256*8]; 2652 static u_char font_14[256*14]; 2653 static u_char font_16[256*16]; 2654#endif 2655 2656 sc_softc_t *sc; 2657 scr_stat *scp; 2658 video_adapter_t *adp; 2659 int col; 2660 int row; 2661 int i; 2662 2663 /* one time initialization */ 2664 if (init_done == COLD) 2665 sc_get_bios_values(&bios_value); 2666 init_done = WARM; 2667 2668 /* 2669 * Allocate resources. Even if we are being called for the second 2670 * time, we must allocate them again, because they might have 2671 * disappeared... 2672 */ 2673 sc = sc_get_softc(unit, flags & SC_KERNEL_CONSOLE); 2674 adp = NULL; 2675 if (sc->adapter >= 0) { 2676 vid_release(sc->adp, (void *)&sc->adapter); 2677 adp = sc->adp; 2678 sc->adp = NULL; 2679 } 2680 if (sc->keyboard >= 0) { 2681 DPRINTF(5, ("sc%d: releasing kbd%d\n", unit, sc->keyboard)); 2682 i = kbd_release(sc->kbd, (void *)&sc->keyboard); 2683 DPRINTF(5, ("sc%d: kbd_release returned %d\n", unit, i)); 2684 if (sc->kbd != NULL) { 2685 DPRINTF(5, ("sc%d: kbd != NULL!, index:%d, unit:%d, flags:0x%x\n", 2686 unit, sc->kbd->kb_index, sc->kbd->kb_unit, sc->kbd->kb_flags)); 2687 } 2688 sc->kbd = NULL; 2689 } 2690 sc->adapter = vid_allocate("*", unit, (void *)&sc->adapter); 2691 sc->adp = vid_get_adapter(sc->adapter); 2692 /* assert((sc->adapter >= 0) && (sc->adp != NULL)) */ 2693 sc->keyboard = kbd_allocate("*", unit, (void *)&sc->keyboard, 2694 sckbdevent, sc); 2695 DPRINTF(1, ("sc%d: keyboard %d\n", unit, sc->keyboard)); 2696 sc->kbd = kbd_get_keyboard(sc->keyboard); 2697 if (sc->kbd != NULL) { 2698 DPRINTF(1, ("sc%d: kbd index:%d, unit:%d, flags:0x%x\n", 2699 unit, sc->kbd->kb_index, sc->kbd->kb_unit, sc->kbd->kb_flags)); 2700 } 2701 2702 if (!(sc->flags & SC_INIT_DONE) || (adp != sc->adp)) { 2703 2704 sc->initial_mode = sc->adp->va_initial_mode; 2705 2706#ifndef SC_NO_FONT_LOADING 2707 if (flags & SC_KERNEL_CONSOLE) { 2708 sc->font_8 = font_8; 2709 sc->font_14 = font_14; 2710 sc->font_16 = font_16; 2711 } else if (sc->font_8 == NULL) { 2712 /* assert(sc_malloc) */ 2713 sc->font_8 = malloc(sizeof(font_8), M_DEVBUF, M_WAITOK); 2714 sc->font_14 = malloc(sizeof(font_14), M_DEVBUF, M_WAITOK); 2715 sc->font_16 = malloc(sizeof(font_16), M_DEVBUF, M_WAITOK); 2716 } 2717#endif 2718 2719 /* extract the hardware cursor location and hide the cursor for now */ 2720 (*vidsw[sc->adapter]->read_hw_cursor)(sc->adp, &col, &row); 2721 (*vidsw[sc->adapter]->set_hw_cursor)(sc->adp, -1, -1); 2722 2723 /* set up the first console */ 2724 sc->first_vty = unit*MAXCONS; 2725 sc->vtys = MAXCONS; /* XXX: should be configurable */ 2726 if (flags & SC_KERNEL_CONSOLE) { 2727 /* 2728 * Set up devs structure but don't use it yet, calling make_dev() 2729 * might panic kernel. Wait for sc_attach_unit() to actually 2730 * create the devices. 2731 */ 2732 sc->dev = main_devs; 2733 scp = &main_console; 2734 init_scp(sc, sc->first_vty, scp); 2735 sc_vtb_init(&scp->vtb, VTB_MEMORY, scp->xsize, scp->ysize, 2736 (void *)sc_buffer, FALSE); 2737 if (sc_init_emulator(scp, SC_DFLT_TERM)) 2738 sc_init_emulator(scp, "*"); 2739 (*scp->tsw->te_default_attr)(scp, 2740 kernel_default.std_color, 2741 kernel_default.rev_color); 2742 } else { 2743 /* assert(sc_malloc) */ 2744 sc->dev = malloc(sizeof(struct cdev *)*sc->vtys, M_DEVBUF, M_WAITOK|M_ZERO); 2745 sc->dev[0] = make_dev(&sc_cdevsw, unit * MAXCONS, 2746 UID_ROOT, GID_WHEEL, 0600, "ttyv%r", unit * MAXCONS); 2747 sc->dev[0]->si_tty = ttymalloc(sc->dev[0]->si_tty); 2748 scp = alloc_scp(sc, sc->first_vty); 2749 SC_STAT(sc->dev[0]) = scp; 2750 } 2751 sc->cur_scp = scp; 2752 2753#ifndef __sparc64__ 2754 /* copy screen to temporary buffer */ 2755 sc_vtb_init(&scp->scr, VTB_FRAMEBUFFER, scp->xsize, scp->ysize, 2756 (void *)scp->sc->adp->va_window, FALSE); 2757 if (ISTEXTSC(scp)) 2758 sc_vtb_copy(&scp->scr, 0, &scp->vtb, 0, scp->xsize*scp->ysize); 2759#endif 2760 2761 /* move cursors to the initial positions */ 2762 if (col >= scp->xsize) 2763 col = 0; 2764 if (row >= scp->ysize) 2765 row = scp->ysize - 1; 2766 scp->xpos = col; 2767 scp->ypos = row; 2768 scp->cursor_pos = scp->cursor_oldpos = row*scp->xsize + col; 2769 2770 if (bios_value.cursor_end < scp->font_size) 2771 sc->dflt_curs_attr.base = scp->font_size - 2772 bios_value.cursor_end - 1; 2773 else 2774 sc->dflt_curs_attr.base = 0; 2775 i = bios_value.cursor_end - bios_value.cursor_start + 1; 2776 sc->dflt_curs_attr.height = imin(i, scp->font_size); 2777 sc->dflt_curs_attr.flags = 0; 2778 sc->curs_attr = sc->dflt_curs_attr; 2779 scp->curr_curs_attr = scp->dflt_curs_attr = sc->curs_attr; 2780 2781#ifndef SC_NO_SYSMOUSE 2782 sc_mouse_move(scp, scp->xpixel/2, scp->ypixel/2); 2783#endif 2784 if (!ISGRAPHSC(scp)) { 2785 sc_set_cursor_image(scp); 2786 sc_draw_cursor_image(scp); 2787 } 2788 2789 /* save font and palette */ 2790#ifndef SC_NO_FONT_LOADING 2791 sc->fonts_loaded = 0; 2792 if (ISFONTAVAIL(sc->adp->va_flags)) { 2793#ifdef SC_DFLT_FONT 2794 bcopy(dflt_font_8, sc->font_8, sizeof(dflt_font_8)); 2795 bcopy(dflt_font_14, sc->font_14, sizeof(dflt_font_14)); 2796 bcopy(dflt_font_16, sc->font_16, sizeof(dflt_font_16)); 2797 sc->fonts_loaded = FONT_16 | FONT_14 | FONT_8; 2798 if (scp->font_size < 14) { 2799 sc_load_font(scp, 0, 8, sc->font_8, 0, 256); 2800 } else if (scp->font_size >= 16) { 2801 sc_load_font(scp, 0, 16, sc->font_16, 0, 256); 2802 } else { 2803 sc_load_font(scp, 0, 14, sc->font_14, 0, 256); 2804 } 2805#else /* !SC_DFLT_FONT */ 2806 if (scp->font_size < 14) { 2807 sc_save_font(scp, 0, 8, sc->font_8, 0, 256); 2808 sc->fonts_loaded = FONT_8; 2809 } else if (scp->font_size >= 16) { 2810 sc_save_font(scp, 0, 16, sc->font_16, 0, 256); 2811 sc->fonts_loaded = FONT_16; 2812 } else { 2813 sc_save_font(scp, 0, 14, sc->font_14, 0, 256); 2814 sc->fonts_loaded = FONT_14; 2815 } 2816#endif /* SC_DFLT_FONT */ 2817 /* FONT KLUDGE: always use the font page #0. XXX */ 2818 sc_show_font(scp, 0); 2819 } 2820#endif /* !SC_NO_FONT_LOADING */ 2821 2822#ifndef SC_NO_PALETTE_LOADING 2823 save_palette(sc->adp, sc->palette); 2824#endif 2825 2826#ifdef DEV_SPLASH 2827 if (!(sc->flags & SC_SPLASH_SCRN) && (flags & SC_KERNEL_CONSOLE)) { 2828 /* we are ready to put up the splash image! */ 2829 splash_init(sc->adp, scsplash_callback, sc); 2830 sc->flags |= SC_SPLASH_SCRN; 2831 } 2832#endif 2833 } 2834 2835 /* the rest is not necessary, if we have done it once */ 2836 if (sc->flags & SC_INIT_DONE) 2837 return; 2838 2839 /* initialize mapscrn arrays to a one to one map */ 2840 for (i = 0; i < sizeof(sc->scr_map); i++) 2841 sc->scr_map[i] = sc->scr_rmap[i] = i; 2842#ifdef PC98 2843 sc->scr_map[0x5c] = (u_char)0xfc; /* for backslash */ 2844#endif 2845 2846 sc->flags |= SC_INIT_DONE; 2847} 2848 2849#if !__alpha__ 2850static void 2851scterm(int unit, int flags) 2852{ 2853 sc_softc_t *sc; 2854 scr_stat *scp; 2855 2856 sc = sc_get_softc(unit, flags & SC_KERNEL_CONSOLE); 2857 if (sc == NULL) 2858 return; /* shouldn't happen */ 2859 2860#ifdef DEV_SPLASH 2861 /* this console is no longer available for the splash screen */ 2862 if (sc->flags & SC_SPLASH_SCRN) { 2863 splash_term(sc->adp); 2864 sc->flags &= ~SC_SPLASH_SCRN; 2865 } 2866#endif 2867 2868#if 0 /* XXX */ 2869 /* move the hardware cursor to the upper-left corner */ 2870 (*vidsw[sc->adapter]->set_hw_cursor)(sc->adp, 0, 0); 2871#endif 2872 2873 /* release the keyboard and the video card */ 2874 if (sc->keyboard >= 0) 2875 kbd_release(sc->kbd, &sc->keyboard); 2876 if (sc->adapter >= 0) 2877 vid_release(sc->adp, &sc->adapter); 2878 2879 /* stop the terminal emulator, if any */ 2880 scp = sc_get_stat(sc->dev[0]); 2881 if (scp->tsw) 2882 (*scp->tsw->te_term)(scp, &scp->ts); 2883 if (scp->ts != NULL) 2884 free(scp->ts, M_DEVBUF); 2885 2886 /* clear the structure */ 2887 if (!(flags & SC_KERNEL_CONSOLE)) { 2888 /* XXX: We need delete_dev() for this */ 2889 free(sc->dev, M_DEVBUF); 2890#if 0 2891 /* XXX: We need a ttyunregister for this */ 2892 free(sc->tty, M_DEVBUF); 2893#endif 2894#ifndef SC_NO_FONT_LOADING 2895 free(sc->font_8, M_DEVBUF); 2896 free(sc->font_14, M_DEVBUF); 2897 free(sc->font_16, M_DEVBUF); 2898#endif 2899 /* XXX vtb, history */ 2900 } 2901 bzero(sc, sizeof(*sc)); 2902 sc->keyboard = -1; 2903 sc->adapter = -1; 2904} 2905#endif /* !__alpha__ */ 2906 2907static void 2908scshutdown(void *arg, int howto) 2909{ 2910 /* assert(sc_console != NULL) */ 2911 2912 sc_touch_scrn_saver(); 2913 if (!cold && sc_console 2914 && sc_console->sc->cur_scp->smode.mode == VT_AUTO 2915 && sc_console->smode.mode == VT_AUTO) 2916 sc_switch_scr(sc_console->sc, sc_console->index); 2917 shutdown_in_progress = TRUE; 2918} 2919 2920int 2921sc_clean_up(scr_stat *scp) 2922{ 2923#ifdef DEV_SPLASH 2924 int error; 2925#endif 2926 2927 if (scp->sc->flags & SC_SCRN_BLANKED) { 2928 sc_touch_scrn_saver(); 2929#ifdef DEV_SPLASH 2930 if ((error = wait_scrn_saver_stop(scp->sc))) 2931 return error; 2932#endif 2933 } 2934 scp->status |= MOUSE_HIDDEN; 2935 sc_remove_mouse_image(scp); 2936 sc_remove_cutmarking(scp); 2937 return 0; 2938} 2939 2940void 2941sc_alloc_scr_buffer(scr_stat *scp, int wait, int discard) 2942{ 2943 sc_vtb_t new; 2944 sc_vtb_t old; 2945 2946 old = scp->vtb; 2947 sc_vtb_init(&new, VTB_MEMORY, scp->xsize, scp->ysize, NULL, wait); 2948 if (!discard && (old.vtb_flags & VTB_VALID)) { 2949 /* retain the current cursor position and buffer contants */ 2950 scp->cursor_oldpos = scp->cursor_pos; 2951 /* 2952 * This works only if the old buffer has the same size as or larger 2953 * than the new one. XXX 2954 */ 2955 sc_vtb_copy(&old, 0, &new, 0, scp->xsize*scp->ysize); 2956 scp->vtb = new; 2957 } else { 2958 scp->vtb = new; 2959 sc_vtb_destroy(&old); 2960 } 2961 2962#ifndef SC_NO_SYSMOUSE 2963 /* move the mouse cursor at the center of the screen */ 2964 sc_mouse_move(scp, scp->xpixel / 2, scp->ypixel / 2); 2965#endif 2966} 2967 2968static scr_stat 2969*alloc_scp(sc_softc_t *sc, int vty) 2970{ 2971 scr_stat *scp; 2972 2973 /* assert(sc_malloc) */ 2974 2975 scp = (scr_stat *)malloc(sizeof(scr_stat), M_DEVBUF, M_WAITOK); 2976 init_scp(sc, vty, scp); 2977 2978 sc_alloc_scr_buffer(scp, TRUE, TRUE); 2979 if (sc_init_emulator(scp, SC_DFLT_TERM)) 2980 sc_init_emulator(scp, "*"); 2981 2982#ifndef SC_NO_CUTPASTE 2983 sc_alloc_cut_buffer(scp, TRUE); 2984#endif 2985 2986#ifndef SC_NO_HISTORY 2987 sc_alloc_history_buffer(scp, 0, 0, TRUE); 2988#endif 2989 2990 return scp; 2991} 2992 2993static void 2994init_scp(sc_softc_t *sc, int vty, scr_stat *scp) 2995{ 2996 video_info_t info; 2997 2998 bzero(scp, sizeof(*scp)); 2999 3000 scp->index = vty; 3001 scp->sc = sc; 3002 scp->status = 0; 3003 scp->mode = sc->initial_mode; 3004 (*vidsw[sc->adapter]->get_info)(sc->adp, scp->mode, &info); 3005 if (info.vi_flags & V_INFO_GRAPHICS) { 3006 scp->status |= GRAPHICS_MODE; 3007 scp->xpixel = info.vi_width; 3008 scp->ypixel = info.vi_height; 3009 scp->xsize = info.vi_width/info.vi_cwidth; 3010 scp->ysize = info.vi_height/info.vi_cheight; 3011 scp->font_size = 0; 3012 scp->font = NULL; 3013 } else { 3014 scp->xsize = info.vi_width; 3015 scp->ysize = info.vi_height; 3016 scp->xpixel = scp->xsize*info.vi_cwidth; 3017 scp->ypixel = scp->ysize*info.vi_cheight; 3018 scp->font_size = info.vi_cheight; 3019 scp->font_width = info.vi_cwidth; 3020 if (info.vi_cheight < 14) { 3021#ifndef SC_NO_FONT_LOADING 3022 scp->font = sc->font_8; 3023#else 3024 scp->font = NULL; 3025#endif 3026 } else if (info.vi_cheight >= 16) { 3027#ifndef SC_NO_FONT_LOADING 3028 scp->font = sc->font_16; 3029#else 3030 scp->font = NULL; 3031#endif 3032 } else { 3033#ifndef SC_NO_FONT_LOADING 3034 scp->font = sc->font_14; 3035#else 3036 scp->font = NULL; 3037#endif 3038 } 3039 } 3040 sc_vtb_init(&scp->vtb, VTB_MEMORY, 0, 0, NULL, FALSE); 3041#ifndef __sparc64__ 3042 sc_vtb_init(&scp->scr, VTB_FRAMEBUFFER, 0, 0, NULL, FALSE); 3043#endif 3044 scp->xoff = scp->yoff = 0; 3045 scp->xpos = scp->ypos = 0; 3046 scp->start = scp->xsize * scp->ysize - 1; 3047 scp->end = 0; 3048 scp->tsw = NULL; 3049 scp->ts = NULL; 3050 scp->rndr = NULL; 3051 scp->border = BG_BLACK; 3052 scp->curr_curs_attr = scp->dflt_curs_attr = sc->curs_attr; 3053 scp->mouse_cut_start = scp->xsize*scp->ysize; 3054 scp->mouse_cut_end = -1; 3055 scp->mouse_signal = 0; 3056 scp->mouse_pid = 0; 3057 scp->mouse_proc = NULL; 3058 scp->kbd_mode = K_XLATE; 3059 scp->bell_pitch = bios_value.bell_pitch; 3060 scp->bell_duration = BELL_DURATION; 3061 scp->status |= (bios_value.shift_state & NLKED); 3062 scp->status |= CURSOR_ENABLED | MOUSE_HIDDEN; 3063 scp->pid = 0; 3064 scp->proc = NULL; 3065 scp->smode.mode = VT_AUTO; 3066 scp->history = NULL; 3067 scp->history_pos = 0; 3068 scp->history_size = 0; 3069} 3070 3071int 3072sc_init_emulator(scr_stat *scp, char *name) 3073{ 3074 sc_term_sw_t *sw; 3075 sc_rndr_sw_t *rndr; 3076 void *p; 3077 int error; 3078 3079 if (name == NULL) /* if no name is given, use the current emulator */ 3080 sw = scp->tsw; 3081 else /* ...otherwise find the named emulator */ 3082 sw = sc_term_match(name); 3083 if (sw == NULL) 3084 return EINVAL; 3085 3086 rndr = NULL; 3087 if (strcmp(sw->te_renderer, "*") != 0) { 3088 rndr = sc_render_match(scp, sw->te_renderer, 3089 scp->status & (GRAPHICS_MODE | PIXEL_MODE)); 3090 } 3091 if (rndr == NULL) { 3092 rndr = sc_render_match(scp, scp->sc->adp->va_name, 3093 scp->status & (GRAPHICS_MODE | PIXEL_MODE)); 3094 if (rndr == NULL) 3095 return ENODEV; 3096 } 3097 3098 if (sw == scp->tsw) { 3099 error = (*sw->te_init)(scp, &scp->ts, SC_TE_WARM_INIT); 3100 scp->rndr = rndr; 3101 sc_clear_screen(scp); 3102 /* assert(error == 0); */ 3103 return error; 3104 } 3105 3106 if (sc_malloc && (sw->te_size > 0)) 3107 p = malloc(sw->te_size, M_DEVBUF, M_NOWAIT); 3108 else 3109 p = NULL; 3110 error = (*sw->te_init)(scp, &p, SC_TE_COLD_INIT); 3111 if (error) 3112 return error; 3113 3114 if (scp->tsw) 3115 (*scp->tsw->te_term)(scp, &scp->ts); 3116 if (scp->ts != NULL) 3117 free(scp->ts, M_DEVBUF); 3118 scp->tsw = sw; 3119 scp->ts = p; 3120 scp->rndr = rndr; 3121 3122 /* XXX */ 3123 (*sw->te_default_attr)(scp, user_default.std_color, user_default.rev_color); 3124 sc_clear_screen(scp); 3125 3126 return 0; 3127} 3128 3129/* 3130 * scgetc(flags) - get character from keyboard. 3131 * If flags & SCGETC_CN, then avoid harmful side effects. 3132 * If flags & SCGETC_NONBLOCK, then wait until a key is pressed, else 3133 * return NOKEY if there is nothing there. 3134 */ 3135static u_int 3136scgetc(sc_softc_t *sc, u_int flags) 3137{ 3138 scr_stat *scp; 3139#ifndef SC_NO_HISTORY 3140 struct tty *tp; 3141#endif 3142 u_int c; 3143 int this_scr; 3144 int f; 3145 int i; 3146 3147 if (sc->kbd == NULL) 3148 return NOKEY; 3149 3150next_code: 3151#if 1 3152 /* I don't like this, but... XXX */ 3153 if (flags & SCGETC_CN) 3154 sccnupdate(sc->cur_scp); 3155#endif 3156 scp = sc->cur_scp; 3157 /* first see if there is something in the keyboard port */ 3158 for (;;) { 3159 c = kbd_read_char(sc->kbd, !(flags & SCGETC_NONBLOCK)); 3160 if (c == ERRKEY) { 3161 if (!(flags & SCGETC_CN)) 3162 sc_bell(scp, bios_value.bell_pitch, BELL_DURATION); 3163 } else if (c == NOKEY) 3164 return c; 3165 else 3166 break; 3167 } 3168 3169 /* make screensaver happy */ 3170 if (!(c & RELKEY)) 3171 sc_touch_scrn_saver(); 3172 3173 if (!(flags & SCGETC_CN)) 3174 random_harvest(&c, sizeof(c), 1, 0, RANDOM_KEYBOARD); 3175 3176 if (scp->kbd_mode != K_XLATE) 3177 return KEYCHAR(c); 3178 3179 /* if scroll-lock pressed allow history browsing */ 3180 if (!ISGRAPHSC(scp) && scp->history && scp->status & SLKED) { 3181 3182 scp->status &= ~CURSOR_ENABLED; 3183 sc_remove_cursor_image(scp); 3184 3185#ifndef SC_NO_HISTORY 3186 if (!(scp->status & BUFFER_SAVED)) { 3187 scp->status |= BUFFER_SAVED; 3188 sc_hist_save(scp); 3189 } 3190 switch (c) { 3191 /* FIXME: key codes */ 3192 case SPCLKEY | FKEY | F(49): /* home key */ 3193 sc_remove_cutmarking(scp); 3194 sc_hist_home(scp); 3195 goto next_code; 3196 3197 case SPCLKEY | FKEY | F(57): /* end key */ 3198 sc_remove_cutmarking(scp); 3199 sc_hist_end(scp); 3200 goto next_code; 3201 3202 case SPCLKEY | FKEY | F(50): /* up arrow key */ 3203 sc_remove_cutmarking(scp); 3204 if (sc_hist_up_line(scp)) 3205 if (!(flags & SCGETC_CN)) 3206 sc_bell(scp, bios_value.bell_pitch, BELL_DURATION); 3207 goto next_code; 3208 3209 case SPCLKEY | FKEY | F(58): /* down arrow key */ 3210 sc_remove_cutmarking(scp); 3211 if (sc_hist_down_line(scp)) 3212 if (!(flags & SCGETC_CN)) 3213 sc_bell(scp, bios_value.bell_pitch, BELL_DURATION); 3214 goto next_code; 3215 3216 case SPCLKEY | FKEY | F(51): /* page up key */ 3217 sc_remove_cutmarking(scp); 3218 for (i=0; i<scp->ysize; i++) 3219 if (sc_hist_up_line(scp)) { 3220 if (!(flags & SCGETC_CN)) 3221 sc_bell(scp, bios_value.bell_pitch, BELL_DURATION); 3222 break; 3223 } 3224 goto next_code; 3225 3226 case SPCLKEY | FKEY | F(59): /* page down key */ 3227 sc_remove_cutmarking(scp); 3228 for (i=0; i<scp->ysize; i++) 3229 if (sc_hist_down_line(scp)) { 3230 if (!(flags & SCGETC_CN)) 3231 sc_bell(scp, bios_value.bell_pitch, BELL_DURATION); 3232 break; 3233 } 3234 goto next_code; 3235 } 3236#endif /* SC_NO_HISTORY */ 3237 } 3238 3239 /* 3240 * Process and consume special keys here. Return a plain char code 3241 * or a char code with the META flag or a function key code. 3242 */ 3243 if (c & RELKEY) { 3244 /* key released */ 3245 /* goto next_code */ 3246 } else { 3247 /* key pressed */ 3248 if (c & SPCLKEY) { 3249 c &= ~SPCLKEY; 3250 switch (KEYCHAR(c)) { 3251 /* LOCKING KEYS */ 3252 case NLK: case CLK: case ALK: 3253 break; 3254 case SLK: 3255 kbd_ioctl(sc->kbd, KDGKBSTATE, (caddr_t)&f); 3256 if (f & SLKED) { 3257 scp->status |= SLKED; 3258 } else { 3259 if (scp->status & SLKED) { 3260 scp->status &= ~SLKED; 3261#ifndef SC_NO_HISTORY 3262 if (scp->status & BUFFER_SAVED) { 3263 if (!sc_hist_restore(scp)) 3264 sc_remove_cutmarking(scp); 3265 scp->status &= ~BUFFER_SAVED; 3266 scp->status |= CURSOR_ENABLED; 3267 sc_draw_cursor_image(scp); 3268 } 3269 tp = VIRTUAL_TTY(sc, scp->index); 3270 if (ISTTYOPEN(tp)) 3271 scstart(tp); 3272#endif 3273 } 3274 } 3275 break; 3276 3277 case PASTE: 3278#ifndef SC_NO_CUTPASTE 3279 sc_mouse_paste(scp); 3280#endif 3281 break; 3282 3283 /* NON-LOCKING KEYS */ 3284 case NOP: 3285 case LSH: case RSH: case LCTR: case RCTR: 3286 case LALT: case RALT: case ASH: case META: 3287 break; 3288 3289 case BTAB: 3290 if (!(sc->flags & SC_SCRN_BLANKED)) 3291 return c; 3292 break; 3293 3294 case SPSC: 3295#ifdef DEV_SPLASH 3296 /* force activatation/deactivation of the screen saver */ 3297 if (!(sc->flags & SC_SCRN_BLANKED)) { 3298 run_scrn_saver = TRUE; 3299 sc->scrn_time_stamp -= scrn_blank_time; 3300 } 3301 if (cold) { 3302 /* 3303 * While devices are being probed, the screen saver need 3304 * to be invoked explictly. XXX 3305 */ 3306 if (sc->flags & SC_SCRN_BLANKED) { 3307 scsplash_stick(FALSE); 3308 stop_scrn_saver(sc, current_saver); 3309 } else { 3310 if (!ISGRAPHSC(scp)) { 3311 scsplash_stick(TRUE); 3312 (*current_saver)(sc, TRUE); 3313 } 3314 } 3315 } 3316#endif /* DEV_SPLASH */ 3317 break; 3318 3319 case RBT: 3320#ifndef SC_DISABLE_REBOOT 3321 shutdown_nice(0); 3322#endif 3323 break; 3324 3325 case HALT: 3326#ifndef SC_DISABLE_REBOOT 3327 shutdown_nice(RB_HALT); 3328#endif 3329 break; 3330 3331 case PDWN: 3332#ifndef SC_DISABLE_REBOOT 3333 shutdown_nice(RB_HALT|RB_POWEROFF); 3334#endif 3335 break; 3336 3337 case SUSP: 3338 power_pm_suspend(POWER_SLEEP_STATE_SUSPEND); 3339 break; 3340 case STBY: 3341 power_pm_suspend(POWER_SLEEP_STATE_STANDBY); 3342 break; 3343 3344 case DBG: 3345#ifndef SC_DISABLE_DDBKEY 3346#ifdef DDB 3347 Debugger("manual escape to debugger"); 3348#else 3349 printf("No debugger in kernel\n"); 3350#endif 3351#else /* SC_DISABLE_DDBKEY */ 3352 /* do nothing */ 3353#endif /* SC_DISABLE_DDBKEY */ 3354 break; 3355 3356 case PNC: 3357 if (enable_panic_key) 3358 panic("Forced by the panic key"); 3359 break; 3360 3361 case NEXT: 3362 this_scr = scp->index; 3363 for (i = (this_scr - sc->first_vty + 1)%sc->vtys; 3364 sc->first_vty + i != this_scr; 3365 i = (i + 1)%sc->vtys) { 3366 struct tty *tp = VIRTUAL_TTY(sc, sc->first_vty + i); 3367 if (ISTTYOPEN(tp)) { 3368 sc_switch_scr(scp->sc, sc->first_vty + i); 3369 break; 3370 } 3371 } 3372 break; 3373 3374 case PREV: 3375 this_scr = scp->index; 3376 for (i = (this_scr - sc->first_vty + sc->vtys - 1)%sc->vtys; 3377 sc->first_vty + i != this_scr; 3378 i = (i + sc->vtys - 1)%sc->vtys) { 3379 struct tty *tp = VIRTUAL_TTY(sc, sc->first_vty + i); 3380 if (ISTTYOPEN(tp)) { 3381 sc_switch_scr(scp->sc, sc->first_vty + i); 3382 break; 3383 } 3384 } 3385 break; 3386 3387 default: 3388 if (KEYCHAR(c) >= F_SCR && KEYCHAR(c) <= L_SCR) { 3389 sc_switch_scr(scp->sc, sc->first_vty + KEYCHAR(c) - F_SCR); 3390 break; 3391 } 3392 /* assert(c & FKEY) */ 3393 if (!(sc->flags & SC_SCRN_BLANKED)) 3394 return c; 3395 break; 3396 } 3397 /* goto next_code */ 3398 } else { 3399 /* regular keys (maybe MKEY is set) */ 3400 if (!(sc->flags & SC_SCRN_BLANKED)) 3401 return c; 3402 } 3403 } 3404 3405 goto next_code; 3406} 3407 3408static int 3409scmmap(struct cdev *dev, vm_offset_t offset, vm_paddr_t *paddr, int nprot) 3410{ 3411 scr_stat *scp; 3412 3413 scp = sc_get_stat(dev); 3414 if (scp != scp->sc->cur_scp) 3415 return -1; 3416 return (*vidsw[scp->sc->adapter]->mmap)(scp->sc->adp, offset, paddr, nprot); 3417} 3418 3419static int 3420save_kbd_state(scr_stat *scp) 3421{ 3422 int state; 3423 int error; 3424 3425 error = kbd_ioctl(scp->sc->kbd, KDGKBSTATE, (caddr_t)&state); 3426 if (error == ENOIOCTL) 3427 error = ENODEV; 3428 if (error == 0) { 3429 scp->status &= ~LOCK_MASK; 3430 scp->status |= state; 3431 } 3432 return error; 3433} 3434 3435static int 3436update_kbd_state(scr_stat *scp, int new_bits, int mask) 3437{ 3438 int state; 3439 int error; 3440 3441 if (mask != LOCK_MASK) { 3442 error = kbd_ioctl(scp->sc->kbd, KDGKBSTATE, (caddr_t)&state); 3443 if (error == ENOIOCTL) 3444 error = ENODEV; 3445 if (error) 3446 return error; 3447 state &= ~mask; 3448 state |= new_bits & mask; 3449 } else { 3450 state = new_bits & LOCK_MASK; 3451 } 3452 error = kbd_ioctl(scp->sc->kbd, KDSKBSTATE, (caddr_t)&state); 3453 if (error == ENOIOCTL) 3454 error = ENODEV; 3455 return error; 3456} 3457 3458static int 3459update_kbd_leds(scr_stat *scp, int which) 3460{ 3461 int error; 3462 3463 which &= LOCK_MASK; 3464 error = kbd_ioctl(scp->sc->kbd, KDSETLED, (caddr_t)&which); 3465 if (error == ENOIOCTL) 3466 error = ENODEV; 3467 return error; 3468} 3469 3470int 3471set_mode(scr_stat *scp) 3472{ 3473 video_info_t info; 3474 3475 /* reject unsupported mode */ 3476 if ((*vidsw[scp->sc->adapter]->get_info)(scp->sc->adp, scp->mode, &info)) 3477 return 1; 3478 3479 /* if this vty is not currently showing, do nothing */ 3480 if (scp != scp->sc->cur_scp) 3481 return 0; 3482 3483 /* setup video hardware for the given mode */ 3484 (*vidsw[scp->sc->adapter]->set_mode)(scp->sc->adp, scp->mode); 3485#ifndef __sparc64__ 3486 sc_vtb_init(&scp->scr, VTB_FRAMEBUFFER, scp->xsize, scp->ysize, 3487 (void *)scp->sc->adp->va_window, FALSE); 3488#endif 3489 3490#ifndef SC_NO_FONT_LOADING 3491 /* load appropriate font */ 3492 if (!(scp->status & GRAPHICS_MODE)) { 3493 if (!(scp->status & PIXEL_MODE) && ISFONTAVAIL(scp->sc->adp->va_flags)) { 3494 if (scp->font_size < 14) { 3495 if (scp->sc->fonts_loaded & FONT_8) 3496 sc_load_font(scp, 0, 8, scp->sc->font_8, 0, 256); 3497 } else if (scp->font_size >= 16) { 3498 if (scp->sc->fonts_loaded & FONT_16) 3499 sc_load_font(scp, 0, 16, scp->sc->font_16, 0, 256); 3500 } else { 3501 if (scp->sc->fonts_loaded & FONT_14) 3502 sc_load_font(scp, 0, 14, scp->sc->font_14, 0, 256); 3503 } 3504 /* 3505 * FONT KLUDGE: 3506 * This is an interim kludge to display correct font. 3507 * Always use the font page #0 on the video plane 2. 3508 * Somehow we cannot show the font in other font pages on 3509 * some video cards... XXX 3510 */ 3511 sc_show_font(scp, 0); 3512 } 3513 mark_all(scp); 3514 } 3515#endif /* !SC_NO_FONT_LOADING */ 3516 3517 sc_set_border(scp, scp->border); 3518 sc_set_cursor_image(scp); 3519 3520 return 0; 3521} 3522 3523void 3524sc_set_border(scr_stat *scp, int color) 3525{ 3526 ++scp->sc->videoio_in_progress; 3527 (*scp->rndr->draw_border)(scp, color); 3528 --scp->sc->videoio_in_progress; 3529} 3530 3531#ifndef SC_NO_FONT_LOADING 3532void 3533sc_load_font(scr_stat *scp, int page, int size, u_char *buf, 3534 int base, int count) 3535{ 3536 sc_softc_t *sc; 3537 3538 sc = scp->sc; 3539 sc->font_loading_in_progress = TRUE; 3540 (*vidsw[sc->adapter]->load_font)(sc->adp, page, size, buf, base, count); 3541 sc->font_loading_in_progress = FALSE; 3542} 3543 3544void 3545sc_save_font(scr_stat *scp, int page, int size, u_char *buf, 3546 int base, int count) 3547{ 3548 sc_softc_t *sc; 3549 3550 sc = scp->sc; 3551 sc->font_loading_in_progress = TRUE; 3552 (*vidsw[sc->adapter]->save_font)(sc->adp, page, size, buf, base, count); 3553 sc->font_loading_in_progress = FALSE; 3554} 3555 3556void 3557sc_show_font(scr_stat *scp, int page) 3558{ 3559 (*vidsw[scp->sc->adapter]->show_font)(scp->sc->adp, page); 3560} 3561#endif /* !SC_NO_FONT_LOADING */ 3562 3563void 3564sc_paste(scr_stat *scp, u_char *p, int count) 3565{ 3566 struct tty *tp; 3567 u_char *rmap; 3568 3569 tp = VIRTUAL_TTY(scp->sc, scp->sc->cur_scp->index); 3570 if (!ISTTYOPEN(tp)) 3571 return; 3572 rmap = scp->sc->scr_rmap; 3573 for (; count > 0; --count) 3574 ttyld_rint(tp, rmap[*p++]); 3575} 3576 3577void 3578sc_bell(scr_stat *scp, int pitch, int duration) 3579{ 3580 if (cold || shutdown_in_progress || !enable_bell) 3581 return; 3582 3583 if (scp != scp->sc->cur_scp && (scp->sc->flags & SC_QUIET_BELL)) 3584 return; 3585 3586 if (scp->sc->flags & SC_VISUAL_BELL) { 3587 if (scp->sc->blink_in_progress) 3588 return; 3589 scp->sc->blink_in_progress = 3; 3590 if (scp != scp->sc->cur_scp) 3591 scp->sc->blink_in_progress += 2; 3592 blink_screen(scp->sc->cur_scp); 3593 } else if (duration != 0 && pitch != 0) { 3594 if (scp != scp->sc->cur_scp) 3595 pitch *= 2; 3596 sysbeep(pitch, duration); 3597 } 3598} 3599 3600static void 3601blink_screen(void *arg) 3602{ 3603 scr_stat *scp = arg; 3604 struct tty *tp; 3605 3606 if (ISGRAPHSC(scp) || (scp->sc->blink_in_progress <= 1)) { 3607 scp->sc->blink_in_progress = 0; 3608 mark_all(scp); 3609 tp = VIRTUAL_TTY(scp->sc, scp->index); 3610 if (ISTTYOPEN(tp)) 3611 scstart(tp); 3612 if (scp->sc->delayed_next_scr) 3613 sc_switch_scr(scp->sc, scp->sc->delayed_next_scr - 1); 3614 } 3615 else { 3616 (*scp->rndr->draw)(scp, 0, scp->xsize*scp->ysize, 3617 scp->sc->blink_in_progress & 1); 3618 scp->sc->blink_in_progress--; 3619 timeout(blink_screen, scp, hz / 10); 3620 } 3621} 3622 3623/* 3624 * Until sc_attach_unit() gets called no dev structures will be available 3625 * to store the per-screen current status. This is the case when the 3626 * kernel is initially booting and needs access to its console. During 3627 * this early phase of booting the console's current status is kept in 3628 * one statically defined scr_stat structure, and any pointers to the 3629 * dev structures will be NULL. 3630 */ 3631 3632static scr_stat * 3633sc_get_stat(struct cdev *devptr) 3634{ 3635 if (devptr == NULL) 3636 return (&main_console); 3637 return (SC_STAT(devptr)); 3638}
| 2626 continue; 2627 if ((scp = sc_get_stat(dev)) == NULL) 2628 continue; 2629 scp->dflt_curs_attr = sc->curs_attr; 2630 change_cursor_shape(scp, CONS_RESET_CURSOR, -1, -1); 2631 } 2632 splx(s); 2633} 2634 2635static void 2636scinit(int unit, int flags) 2637{ 2638 /* 2639 * When syscons is being initialized as the kernel console, malloc() 2640 * is not yet functional, because various kernel structures has not been 2641 * fully initialized yet. Therefore, we need to declare the following 2642 * static buffers for the console. This is less than ideal, 2643 * but is necessry evil for the time being. XXX 2644 */ 2645#ifdef PC98 2646 static u_short sc_buffer[ROW*COL*2];/* XXX */ 2647#else 2648 static u_short sc_buffer[ROW*COL]; /* XXX */ 2649#endif 2650#ifndef SC_NO_FONT_LOADING 2651 static u_char font_8[256*8]; 2652 static u_char font_14[256*14]; 2653 static u_char font_16[256*16]; 2654#endif 2655 2656 sc_softc_t *sc; 2657 scr_stat *scp; 2658 video_adapter_t *adp; 2659 int col; 2660 int row; 2661 int i; 2662 2663 /* one time initialization */ 2664 if (init_done == COLD) 2665 sc_get_bios_values(&bios_value); 2666 init_done = WARM; 2667 2668 /* 2669 * Allocate resources. Even if we are being called for the second 2670 * time, we must allocate them again, because they might have 2671 * disappeared... 2672 */ 2673 sc = sc_get_softc(unit, flags & SC_KERNEL_CONSOLE); 2674 adp = NULL; 2675 if (sc->adapter >= 0) { 2676 vid_release(sc->adp, (void *)&sc->adapter); 2677 adp = sc->adp; 2678 sc->adp = NULL; 2679 } 2680 if (sc->keyboard >= 0) { 2681 DPRINTF(5, ("sc%d: releasing kbd%d\n", unit, sc->keyboard)); 2682 i = kbd_release(sc->kbd, (void *)&sc->keyboard); 2683 DPRINTF(5, ("sc%d: kbd_release returned %d\n", unit, i)); 2684 if (sc->kbd != NULL) { 2685 DPRINTF(5, ("sc%d: kbd != NULL!, index:%d, unit:%d, flags:0x%x\n", 2686 unit, sc->kbd->kb_index, sc->kbd->kb_unit, sc->kbd->kb_flags)); 2687 } 2688 sc->kbd = NULL; 2689 } 2690 sc->adapter = vid_allocate("*", unit, (void *)&sc->adapter); 2691 sc->adp = vid_get_adapter(sc->adapter); 2692 /* assert((sc->adapter >= 0) && (sc->adp != NULL)) */ 2693 sc->keyboard = kbd_allocate("*", unit, (void *)&sc->keyboard, 2694 sckbdevent, sc); 2695 DPRINTF(1, ("sc%d: keyboard %d\n", unit, sc->keyboard)); 2696 sc->kbd = kbd_get_keyboard(sc->keyboard); 2697 if (sc->kbd != NULL) { 2698 DPRINTF(1, ("sc%d: kbd index:%d, unit:%d, flags:0x%x\n", 2699 unit, sc->kbd->kb_index, sc->kbd->kb_unit, sc->kbd->kb_flags)); 2700 } 2701 2702 if (!(sc->flags & SC_INIT_DONE) || (adp != sc->adp)) { 2703 2704 sc->initial_mode = sc->adp->va_initial_mode; 2705 2706#ifndef SC_NO_FONT_LOADING 2707 if (flags & SC_KERNEL_CONSOLE) { 2708 sc->font_8 = font_8; 2709 sc->font_14 = font_14; 2710 sc->font_16 = font_16; 2711 } else if (sc->font_8 == NULL) { 2712 /* assert(sc_malloc) */ 2713 sc->font_8 = malloc(sizeof(font_8), M_DEVBUF, M_WAITOK); 2714 sc->font_14 = malloc(sizeof(font_14), M_DEVBUF, M_WAITOK); 2715 sc->font_16 = malloc(sizeof(font_16), M_DEVBUF, M_WAITOK); 2716 } 2717#endif 2718 2719 /* extract the hardware cursor location and hide the cursor for now */ 2720 (*vidsw[sc->adapter]->read_hw_cursor)(sc->adp, &col, &row); 2721 (*vidsw[sc->adapter]->set_hw_cursor)(sc->adp, -1, -1); 2722 2723 /* set up the first console */ 2724 sc->first_vty = unit*MAXCONS; 2725 sc->vtys = MAXCONS; /* XXX: should be configurable */ 2726 if (flags & SC_KERNEL_CONSOLE) { 2727 /* 2728 * Set up devs structure but don't use it yet, calling make_dev() 2729 * might panic kernel. Wait for sc_attach_unit() to actually 2730 * create the devices. 2731 */ 2732 sc->dev = main_devs; 2733 scp = &main_console; 2734 init_scp(sc, sc->first_vty, scp); 2735 sc_vtb_init(&scp->vtb, VTB_MEMORY, scp->xsize, scp->ysize, 2736 (void *)sc_buffer, FALSE); 2737 if (sc_init_emulator(scp, SC_DFLT_TERM)) 2738 sc_init_emulator(scp, "*"); 2739 (*scp->tsw->te_default_attr)(scp, 2740 kernel_default.std_color, 2741 kernel_default.rev_color); 2742 } else { 2743 /* assert(sc_malloc) */ 2744 sc->dev = malloc(sizeof(struct cdev *)*sc->vtys, M_DEVBUF, M_WAITOK|M_ZERO); 2745 sc->dev[0] = make_dev(&sc_cdevsw, unit * MAXCONS, 2746 UID_ROOT, GID_WHEEL, 0600, "ttyv%r", unit * MAXCONS); 2747 sc->dev[0]->si_tty = ttymalloc(sc->dev[0]->si_tty); 2748 scp = alloc_scp(sc, sc->first_vty); 2749 SC_STAT(sc->dev[0]) = scp; 2750 } 2751 sc->cur_scp = scp; 2752 2753#ifndef __sparc64__ 2754 /* copy screen to temporary buffer */ 2755 sc_vtb_init(&scp->scr, VTB_FRAMEBUFFER, scp->xsize, scp->ysize, 2756 (void *)scp->sc->adp->va_window, FALSE); 2757 if (ISTEXTSC(scp)) 2758 sc_vtb_copy(&scp->scr, 0, &scp->vtb, 0, scp->xsize*scp->ysize); 2759#endif 2760 2761 /* move cursors to the initial positions */ 2762 if (col >= scp->xsize) 2763 col = 0; 2764 if (row >= scp->ysize) 2765 row = scp->ysize - 1; 2766 scp->xpos = col; 2767 scp->ypos = row; 2768 scp->cursor_pos = scp->cursor_oldpos = row*scp->xsize + col; 2769 2770 if (bios_value.cursor_end < scp->font_size) 2771 sc->dflt_curs_attr.base = scp->font_size - 2772 bios_value.cursor_end - 1; 2773 else 2774 sc->dflt_curs_attr.base = 0; 2775 i = bios_value.cursor_end - bios_value.cursor_start + 1; 2776 sc->dflt_curs_attr.height = imin(i, scp->font_size); 2777 sc->dflt_curs_attr.flags = 0; 2778 sc->curs_attr = sc->dflt_curs_attr; 2779 scp->curr_curs_attr = scp->dflt_curs_attr = sc->curs_attr; 2780 2781#ifndef SC_NO_SYSMOUSE 2782 sc_mouse_move(scp, scp->xpixel/2, scp->ypixel/2); 2783#endif 2784 if (!ISGRAPHSC(scp)) { 2785 sc_set_cursor_image(scp); 2786 sc_draw_cursor_image(scp); 2787 } 2788 2789 /* save font and palette */ 2790#ifndef SC_NO_FONT_LOADING 2791 sc->fonts_loaded = 0; 2792 if (ISFONTAVAIL(sc->adp->va_flags)) { 2793#ifdef SC_DFLT_FONT 2794 bcopy(dflt_font_8, sc->font_8, sizeof(dflt_font_8)); 2795 bcopy(dflt_font_14, sc->font_14, sizeof(dflt_font_14)); 2796 bcopy(dflt_font_16, sc->font_16, sizeof(dflt_font_16)); 2797 sc->fonts_loaded = FONT_16 | FONT_14 | FONT_8; 2798 if (scp->font_size < 14) { 2799 sc_load_font(scp, 0, 8, sc->font_8, 0, 256); 2800 } else if (scp->font_size >= 16) { 2801 sc_load_font(scp, 0, 16, sc->font_16, 0, 256); 2802 } else { 2803 sc_load_font(scp, 0, 14, sc->font_14, 0, 256); 2804 } 2805#else /* !SC_DFLT_FONT */ 2806 if (scp->font_size < 14) { 2807 sc_save_font(scp, 0, 8, sc->font_8, 0, 256); 2808 sc->fonts_loaded = FONT_8; 2809 } else if (scp->font_size >= 16) { 2810 sc_save_font(scp, 0, 16, sc->font_16, 0, 256); 2811 sc->fonts_loaded = FONT_16; 2812 } else { 2813 sc_save_font(scp, 0, 14, sc->font_14, 0, 256); 2814 sc->fonts_loaded = FONT_14; 2815 } 2816#endif /* SC_DFLT_FONT */ 2817 /* FONT KLUDGE: always use the font page #0. XXX */ 2818 sc_show_font(scp, 0); 2819 } 2820#endif /* !SC_NO_FONT_LOADING */ 2821 2822#ifndef SC_NO_PALETTE_LOADING 2823 save_palette(sc->adp, sc->palette); 2824#endif 2825 2826#ifdef DEV_SPLASH 2827 if (!(sc->flags & SC_SPLASH_SCRN) && (flags & SC_KERNEL_CONSOLE)) { 2828 /* we are ready to put up the splash image! */ 2829 splash_init(sc->adp, scsplash_callback, sc); 2830 sc->flags |= SC_SPLASH_SCRN; 2831 } 2832#endif 2833 } 2834 2835 /* the rest is not necessary, if we have done it once */ 2836 if (sc->flags & SC_INIT_DONE) 2837 return; 2838 2839 /* initialize mapscrn arrays to a one to one map */ 2840 for (i = 0; i < sizeof(sc->scr_map); i++) 2841 sc->scr_map[i] = sc->scr_rmap[i] = i; 2842#ifdef PC98 2843 sc->scr_map[0x5c] = (u_char)0xfc; /* for backslash */ 2844#endif 2845 2846 sc->flags |= SC_INIT_DONE; 2847} 2848 2849#if !__alpha__ 2850static void 2851scterm(int unit, int flags) 2852{ 2853 sc_softc_t *sc; 2854 scr_stat *scp; 2855 2856 sc = sc_get_softc(unit, flags & SC_KERNEL_CONSOLE); 2857 if (sc == NULL) 2858 return; /* shouldn't happen */ 2859 2860#ifdef DEV_SPLASH 2861 /* this console is no longer available for the splash screen */ 2862 if (sc->flags & SC_SPLASH_SCRN) { 2863 splash_term(sc->adp); 2864 sc->flags &= ~SC_SPLASH_SCRN; 2865 } 2866#endif 2867 2868#if 0 /* XXX */ 2869 /* move the hardware cursor to the upper-left corner */ 2870 (*vidsw[sc->adapter]->set_hw_cursor)(sc->adp, 0, 0); 2871#endif 2872 2873 /* release the keyboard and the video card */ 2874 if (sc->keyboard >= 0) 2875 kbd_release(sc->kbd, &sc->keyboard); 2876 if (sc->adapter >= 0) 2877 vid_release(sc->adp, &sc->adapter); 2878 2879 /* stop the terminal emulator, if any */ 2880 scp = sc_get_stat(sc->dev[0]); 2881 if (scp->tsw) 2882 (*scp->tsw->te_term)(scp, &scp->ts); 2883 if (scp->ts != NULL) 2884 free(scp->ts, M_DEVBUF); 2885 2886 /* clear the structure */ 2887 if (!(flags & SC_KERNEL_CONSOLE)) { 2888 /* XXX: We need delete_dev() for this */ 2889 free(sc->dev, M_DEVBUF); 2890#if 0 2891 /* XXX: We need a ttyunregister for this */ 2892 free(sc->tty, M_DEVBUF); 2893#endif 2894#ifndef SC_NO_FONT_LOADING 2895 free(sc->font_8, M_DEVBUF); 2896 free(sc->font_14, M_DEVBUF); 2897 free(sc->font_16, M_DEVBUF); 2898#endif 2899 /* XXX vtb, history */ 2900 } 2901 bzero(sc, sizeof(*sc)); 2902 sc->keyboard = -1; 2903 sc->adapter = -1; 2904} 2905#endif /* !__alpha__ */ 2906 2907static void 2908scshutdown(void *arg, int howto) 2909{ 2910 /* assert(sc_console != NULL) */ 2911 2912 sc_touch_scrn_saver(); 2913 if (!cold && sc_console 2914 && sc_console->sc->cur_scp->smode.mode == VT_AUTO 2915 && sc_console->smode.mode == VT_AUTO) 2916 sc_switch_scr(sc_console->sc, sc_console->index); 2917 shutdown_in_progress = TRUE; 2918} 2919 2920int 2921sc_clean_up(scr_stat *scp) 2922{ 2923#ifdef DEV_SPLASH 2924 int error; 2925#endif 2926 2927 if (scp->sc->flags & SC_SCRN_BLANKED) { 2928 sc_touch_scrn_saver(); 2929#ifdef DEV_SPLASH 2930 if ((error = wait_scrn_saver_stop(scp->sc))) 2931 return error; 2932#endif 2933 } 2934 scp->status |= MOUSE_HIDDEN; 2935 sc_remove_mouse_image(scp); 2936 sc_remove_cutmarking(scp); 2937 return 0; 2938} 2939 2940void 2941sc_alloc_scr_buffer(scr_stat *scp, int wait, int discard) 2942{ 2943 sc_vtb_t new; 2944 sc_vtb_t old; 2945 2946 old = scp->vtb; 2947 sc_vtb_init(&new, VTB_MEMORY, scp->xsize, scp->ysize, NULL, wait); 2948 if (!discard && (old.vtb_flags & VTB_VALID)) { 2949 /* retain the current cursor position and buffer contants */ 2950 scp->cursor_oldpos = scp->cursor_pos; 2951 /* 2952 * This works only if the old buffer has the same size as or larger 2953 * than the new one. XXX 2954 */ 2955 sc_vtb_copy(&old, 0, &new, 0, scp->xsize*scp->ysize); 2956 scp->vtb = new; 2957 } else { 2958 scp->vtb = new; 2959 sc_vtb_destroy(&old); 2960 } 2961 2962#ifndef SC_NO_SYSMOUSE 2963 /* move the mouse cursor at the center of the screen */ 2964 sc_mouse_move(scp, scp->xpixel / 2, scp->ypixel / 2); 2965#endif 2966} 2967 2968static scr_stat 2969*alloc_scp(sc_softc_t *sc, int vty) 2970{ 2971 scr_stat *scp; 2972 2973 /* assert(sc_malloc) */ 2974 2975 scp = (scr_stat *)malloc(sizeof(scr_stat), M_DEVBUF, M_WAITOK); 2976 init_scp(sc, vty, scp); 2977 2978 sc_alloc_scr_buffer(scp, TRUE, TRUE); 2979 if (sc_init_emulator(scp, SC_DFLT_TERM)) 2980 sc_init_emulator(scp, "*"); 2981 2982#ifndef SC_NO_CUTPASTE 2983 sc_alloc_cut_buffer(scp, TRUE); 2984#endif 2985 2986#ifndef SC_NO_HISTORY 2987 sc_alloc_history_buffer(scp, 0, 0, TRUE); 2988#endif 2989 2990 return scp; 2991} 2992 2993static void 2994init_scp(sc_softc_t *sc, int vty, scr_stat *scp) 2995{ 2996 video_info_t info; 2997 2998 bzero(scp, sizeof(*scp)); 2999 3000 scp->index = vty; 3001 scp->sc = sc; 3002 scp->status = 0; 3003 scp->mode = sc->initial_mode; 3004 (*vidsw[sc->adapter]->get_info)(sc->adp, scp->mode, &info); 3005 if (info.vi_flags & V_INFO_GRAPHICS) { 3006 scp->status |= GRAPHICS_MODE; 3007 scp->xpixel = info.vi_width; 3008 scp->ypixel = info.vi_height; 3009 scp->xsize = info.vi_width/info.vi_cwidth; 3010 scp->ysize = info.vi_height/info.vi_cheight; 3011 scp->font_size = 0; 3012 scp->font = NULL; 3013 } else { 3014 scp->xsize = info.vi_width; 3015 scp->ysize = info.vi_height; 3016 scp->xpixel = scp->xsize*info.vi_cwidth; 3017 scp->ypixel = scp->ysize*info.vi_cheight; 3018 scp->font_size = info.vi_cheight; 3019 scp->font_width = info.vi_cwidth; 3020 if (info.vi_cheight < 14) { 3021#ifndef SC_NO_FONT_LOADING 3022 scp->font = sc->font_8; 3023#else 3024 scp->font = NULL; 3025#endif 3026 } else if (info.vi_cheight >= 16) { 3027#ifndef SC_NO_FONT_LOADING 3028 scp->font = sc->font_16; 3029#else 3030 scp->font = NULL; 3031#endif 3032 } else { 3033#ifndef SC_NO_FONT_LOADING 3034 scp->font = sc->font_14; 3035#else 3036 scp->font = NULL; 3037#endif 3038 } 3039 } 3040 sc_vtb_init(&scp->vtb, VTB_MEMORY, 0, 0, NULL, FALSE); 3041#ifndef __sparc64__ 3042 sc_vtb_init(&scp->scr, VTB_FRAMEBUFFER, 0, 0, NULL, FALSE); 3043#endif 3044 scp->xoff = scp->yoff = 0; 3045 scp->xpos = scp->ypos = 0; 3046 scp->start = scp->xsize * scp->ysize - 1; 3047 scp->end = 0; 3048 scp->tsw = NULL; 3049 scp->ts = NULL; 3050 scp->rndr = NULL; 3051 scp->border = BG_BLACK; 3052 scp->curr_curs_attr = scp->dflt_curs_attr = sc->curs_attr; 3053 scp->mouse_cut_start = scp->xsize*scp->ysize; 3054 scp->mouse_cut_end = -1; 3055 scp->mouse_signal = 0; 3056 scp->mouse_pid = 0; 3057 scp->mouse_proc = NULL; 3058 scp->kbd_mode = K_XLATE; 3059 scp->bell_pitch = bios_value.bell_pitch; 3060 scp->bell_duration = BELL_DURATION; 3061 scp->status |= (bios_value.shift_state & NLKED); 3062 scp->status |= CURSOR_ENABLED | MOUSE_HIDDEN; 3063 scp->pid = 0; 3064 scp->proc = NULL; 3065 scp->smode.mode = VT_AUTO; 3066 scp->history = NULL; 3067 scp->history_pos = 0; 3068 scp->history_size = 0; 3069} 3070 3071int 3072sc_init_emulator(scr_stat *scp, char *name) 3073{ 3074 sc_term_sw_t *sw; 3075 sc_rndr_sw_t *rndr; 3076 void *p; 3077 int error; 3078 3079 if (name == NULL) /* if no name is given, use the current emulator */ 3080 sw = scp->tsw; 3081 else /* ...otherwise find the named emulator */ 3082 sw = sc_term_match(name); 3083 if (sw == NULL) 3084 return EINVAL; 3085 3086 rndr = NULL; 3087 if (strcmp(sw->te_renderer, "*") != 0) { 3088 rndr = sc_render_match(scp, sw->te_renderer, 3089 scp->status & (GRAPHICS_MODE | PIXEL_MODE)); 3090 } 3091 if (rndr == NULL) { 3092 rndr = sc_render_match(scp, scp->sc->adp->va_name, 3093 scp->status & (GRAPHICS_MODE | PIXEL_MODE)); 3094 if (rndr == NULL) 3095 return ENODEV; 3096 } 3097 3098 if (sw == scp->tsw) { 3099 error = (*sw->te_init)(scp, &scp->ts, SC_TE_WARM_INIT); 3100 scp->rndr = rndr; 3101 sc_clear_screen(scp); 3102 /* assert(error == 0); */ 3103 return error; 3104 } 3105 3106 if (sc_malloc && (sw->te_size > 0)) 3107 p = malloc(sw->te_size, M_DEVBUF, M_NOWAIT); 3108 else 3109 p = NULL; 3110 error = (*sw->te_init)(scp, &p, SC_TE_COLD_INIT); 3111 if (error) 3112 return error; 3113 3114 if (scp->tsw) 3115 (*scp->tsw->te_term)(scp, &scp->ts); 3116 if (scp->ts != NULL) 3117 free(scp->ts, M_DEVBUF); 3118 scp->tsw = sw; 3119 scp->ts = p; 3120 scp->rndr = rndr; 3121 3122 /* XXX */ 3123 (*sw->te_default_attr)(scp, user_default.std_color, user_default.rev_color); 3124 sc_clear_screen(scp); 3125 3126 return 0; 3127} 3128 3129/* 3130 * scgetc(flags) - get character from keyboard. 3131 * If flags & SCGETC_CN, then avoid harmful side effects. 3132 * If flags & SCGETC_NONBLOCK, then wait until a key is pressed, else 3133 * return NOKEY if there is nothing there. 3134 */ 3135static u_int 3136scgetc(sc_softc_t *sc, u_int flags) 3137{ 3138 scr_stat *scp; 3139#ifndef SC_NO_HISTORY 3140 struct tty *tp; 3141#endif 3142 u_int c; 3143 int this_scr; 3144 int f; 3145 int i; 3146 3147 if (sc->kbd == NULL) 3148 return NOKEY; 3149 3150next_code: 3151#if 1 3152 /* I don't like this, but... XXX */ 3153 if (flags & SCGETC_CN) 3154 sccnupdate(sc->cur_scp); 3155#endif 3156 scp = sc->cur_scp; 3157 /* first see if there is something in the keyboard port */ 3158 for (;;) { 3159 c = kbd_read_char(sc->kbd, !(flags & SCGETC_NONBLOCK)); 3160 if (c == ERRKEY) { 3161 if (!(flags & SCGETC_CN)) 3162 sc_bell(scp, bios_value.bell_pitch, BELL_DURATION); 3163 } else if (c == NOKEY) 3164 return c; 3165 else 3166 break; 3167 } 3168 3169 /* make screensaver happy */ 3170 if (!(c & RELKEY)) 3171 sc_touch_scrn_saver(); 3172 3173 if (!(flags & SCGETC_CN)) 3174 random_harvest(&c, sizeof(c), 1, 0, RANDOM_KEYBOARD); 3175 3176 if (scp->kbd_mode != K_XLATE) 3177 return KEYCHAR(c); 3178 3179 /* if scroll-lock pressed allow history browsing */ 3180 if (!ISGRAPHSC(scp) && scp->history && scp->status & SLKED) { 3181 3182 scp->status &= ~CURSOR_ENABLED; 3183 sc_remove_cursor_image(scp); 3184 3185#ifndef SC_NO_HISTORY 3186 if (!(scp->status & BUFFER_SAVED)) { 3187 scp->status |= BUFFER_SAVED; 3188 sc_hist_save(scp); 3189 } 3190 switch (c) { 3191 /* FIXME: key codes */ 3192 case SPCLKEY | FKEY | F(49): /* home key */ 3193 sc_remove_cutmarking(scp); 3194 sc_hist_home(scp); 3195 goto next_code; 3196 3197 case SPCLKEY | FKEY | F(57): /* end key */ 3198 sc_remove_cutmarking(scp); 3199 sc_hist_end(scp); 3200 goto next_code; 3201 3202 case SPCLKEY | FKEY | F(50): /* up arrow key */ 3203 sc_remove_cutmarking(scp); 3204 if (sc_hist_up_line(scp)) 3205 if (!(flags & SCGETC_CN)) 3206 sc_bell(scp, bios_value.bell_pitch, BELL_DURATION); 3207 goto next_code; 3208 3209 case SPCLKEY | FKEY | F(58): /* down arrow key */ 3210 sc_remove_cutmarking(scp); 3211 if (sc_hist_down_line(scp)) 3212 if (!(flags & SCGETC_CN)) 3213 sc_bell(scp, bios_value.bell_pitch, BELL_DURATION); 3214 goto next_code; 3215 3216 case SPCLKEY | FKEY | F(51): /* page up key */ 3217 sc_remove_cutmarking(scp); 3218 for (i=0; i<scp->ysize; i++) 3219 if (sc_hist_up_line(scp)) { 3220 if (!(flags & SCGETC_CN)) 3221 sc_bell(scp, bios_value.bell_pitch, BELL_DURATION); 3222 break; 3223 } 3224 goto next_code; 3225 3226 case SPCLKEY | FKEY | F(59): /* page down key */ 3227 sc_remove_cutmarking(scp); 3228 for (i=0; i<scp->ysize; i++) 3229 if (sc_hist_down_line(scp)) { 3230 if (!(flags & SCGETC_CN)) 3231 sc_bell(scp, bios_value.bell_pitch, BELL_DURATION); 3232 break; 3233 } 3234 goto next_code; 3235 } 3236#endif /* SC_NO_HISTORY */ 3237 } 3238 3239 /* 3240 * Process and consume special keys here. Return a plain char code 3241 * or a char code with the META flag or a function key code. 3242 */ 3243 if (c & RELKEY) { 3244 /* key released */ 3245 /* goto next_code */ 3246 } else { 3247 /* key pressed */ 3248 if (c & SPCLKEY) { 3249 c &= ~SPCLKEY; 3250 switch (KEYCHAR(c)) { 3251 /* LOCKING KEYS */ 3252 case NLK: case CLK: case ALK: 3253 break; 3254 case SLK: 3255 kbd_ioctl(sc->kbd, KDGKBSTATE, (caddr_t)&f); 3256 if (f & SLKED) { 3257 scp->status |= SLKED; 3258 } else { 3259 if (scp->status & SLKED) { 3260 scp->status &= ~SLKED; 3261#ifndef SC_NO_HISTORY 3262 if (scp->status & BUFFER_SAVED) { 3263 if (!sc_hist_restore(scp)) 3264 sc_remove_cutmarking(scp); 3265 scp->status &= ~BUFFER_SAVED; 3266 scp->status |= CURSOR_ENABLED; 3267 sc_draw_cursor_image(scp); 3268 } 3269 tp = VIRTUAL_TTY(sc, scp->index); 3270 if (ISTTYOPEN(tp)) 3271 scstart(tp); 3272#endif 3273 } 3274 } 3275 break; 3276 3277 case PASTE: 3278#ifndef SC_NO_CUTPASTE 3279 sc_mouse_paste(scp); 3280#endif 3281 break; 3282 3283 /* NON-LOCKING KEYS */ 3284 case NOP: 3285 case LSH: case RSH: case LCTR: case RCTR: 3286 case LALT: case RALT: case ASH: case META: 3287 break; 3288 3289 case BTAB: 3290 if (!(sc->flags & SC_SCRN_BLANKED)) 3291 return c; 3292 break; 3293 3294 case SPSC: 3295#ifdef DEV_SPLASH 3296 /* force activatation/deactivation of the screen saver */ 3297 if (!(sc->flags & SC_SCRN_BLANKED)) { 3298 run_scrn_saver = TRUE; 3299 sc->scrn_time_stamp -= scrn_blank_time; 3300 } 3301 if (cold) { 3302 /* 3303 * While devices are being probed, the screen saver need 3304 * to be invoked explictly. XXX 3305 */ 3306 if (sc->flags & SC_SCRN_BLANKED) { 3307 scsplash_stick(FALSE); 3308 stop_scrn_saver(sc, current_saver); 3309 } else { 3310 if (!ISGRAPHSC(scp)) { 3311 scsplash_stick(TRUE); 3312 (*current_saver)(sc, TRUE); 3313 } 3314 } 3315 } 3316#endif /* DEV_SPLASH */ 3317 break; 3318 3319 case RBT: 3320#ifndef SC_DISABLE_REBOOT 3321 shutdown_nice(0); 3322#endif 3323 break; 3324 3325 case HALT: 3326#ifndef SC_DISABLE_REBOOT 3327 shutdown_nice(RB_HALT); 3328#endif 3329 break; 3330 3331 case PDWN: 3332#ifndef SC_DISABLE_REBOOT 3333 shutdown_nice(RB_HALT|RB_POWEROFF); 3334#endif 3335 break; 3336 3337 case SUSP: 3338 power_pm_suspend(POWER_SLEEP_STATE_SUSPEND); 3339 break; 3340 case STBY: 3341 power_pm_suspend(POWER_SLEEP_STATE_STANDBY); 3342 break; 3343 3344 case DBG: 3345#ifndef SC_DISABLE_DDBKEY 3346#ifdef DDB 3347 Debugger("manual escape to debugger"); 3348#else 3349 printf("No debugger in kernel\n"); 3350#endif 3351#else /* SC_DISABLE_DDBKEY */ 3352 /* do nothing */ 3353#endif /* SC_DISABLE_DDBKEY */ 3354 break; 3355 3356 case PNC: 3357 if (enable_panic_key) 3358 panic("Forced by the panic key"); 3359 break; 3360 3361 case NEXT: 3362 this_scr = scp->index; 3363 for (i = (this_scr - sc->first_vty + 1)%sc->vtys; 3364 sc->first_vty + i != this_scr; 3365 i = (i + 1)%sc->vtys) { 3366 struct tty *tp = VIRTUAL_TTY(sc, sc->first_vty + i); 3367 if (ISTTYOPEN(tp)) { 3368 sc_switch_scr(scp->sc, sc->first_vty + i); 3369 break; 3370 } 3371 } 3372 break; 3373 3374 case PREV: 3375 this_scr = scp->index; 3376 for (i = (this_scr - sc->first_vty + sc->vtys - 1)%sc->vtys; 3377 sc->first_vty + i != this_scr; 3378 i = (i + sc->vtys - 1)%sc->vtys) { 3379 struct tty *tp = VIRTUAL_TTY(sc, sc->first_vty + i); 3380 if (ISTTYOPEN(tp)) { 3381 sc_switch_scr(scp->sc, sc->first_vty + i); 3382 break; 3383 } 3384 } 3385 break; 3386 3387 default: 3388 if (KEYCHAR(c) >= F_SCR && KEYCHAR(c) <= L_SCR) { 3389 sc_switch_scr(scp->sc, sc->first_vty + KEYCHAR(c) - F_SCR); 3390 break; 3391 } 3392 /* assert(c & FKEY) */ 3393 if (!(sc->flags & SC_SCRN_BLANKED)) 3394 return c; 3395 break; 3396 } 3397 /* goto next_code */ 3398 } else { 3399 /* regular keys (maybe MKEY is set) */ 3400 if (!(sc->flags & SC_SCRN_BLANKED)) 3401 return c; 3402 } 3403 } 3404 3405 goto next_code; 3406} 3407 3408static int 3409scmmap(struct cdev *dev, vm_offset_t offset, vm_paddr_t *paddr, int nprot) 3410{ 3411 scr_stat *scp; 3412 3413 scp = sc_get_stat(dev); 3414 if (scp != scp->sc->cur_scp) 3415 return -1; 3416 return (*vidsw[scp->sc->adapter]->mmap)(scp->sc->adp, offset, paddr, nprot); 3417} 3418 3419static int 3420save_kbd_state(scr_stat *scp) 3421{ 3422 int state; 3423 int error; 3424 3425 error = kbd_ioctl(scp->sc->kbd, KDGKBSTATE, (caddr_t)&state); 3426 if (error == ENOIOCTL) 3427 error = ENODEV; 3428 if (error == 0) { 3429 scp->status &= ~LOCK_MASK; 3430 scp->status |= state; 3431 } 3432 return error; 3433} 3434 3435static int 3436update_kbd_state(scr_stat *scp, int new_bits, int mask) 3437{ 3438 int state; 3439 int error; 3440 3441 if (mask != LOCK_MASK) { 3442 error = kbd_ioctl(scp->sc->kbd, KDGKBSTATE, (caddr_t)&state); 3443 if (error == ENOIOCTL) 3444 error = ENODEV; 3445 if (error) 3446 return error; 3447 state &= ~mask; 3448 state |= new_bits & mask; 3449 } else { 3450 state = new_bits & LOCK_MASK; 3451 } 3452 error = kbd_ioctl(scp->sc->kbd, KDSKBSTATE, (caddr_t)&state); 3453 if (error == ENOIOCTL) 3454 error = ENODEV; 3455 return error; 3456} 3457 3458static int 3459update_kbd_leds(scr_stat *scp, int which) 3460{ 3461 int error; 3462 3463 which &= LOCK_MASK; 3464 error = kbd_ioctl(scp->sc->kbd, KDSETLED, (caddr_t)&which); 3465 if (error == ENOIOCTL) 3466 error = ENODEV; 3467 return error; 3468} 3469 3470int 3471set_mode(scr_stat *scp) 3472{ 3473 video_info_t info; 3474 3475 /* reject unsupported mode */ 3476 if ((*vidsw[scp->sc->adapter]->get_info)(scp->sc->adp, scp->mode, &info)) 3477 return 1; 3478 3479 /* if this vty is not currently showing, do nothing */ 3480 if (scp != scp->sc->cur_scp) 3481 return 0; 3482 3483 /* setup video hardware for the given mode */ 3484 (*vidsw[scp->sc->adapter]->set_mode)(scp->sc->adp, scp->mode); 3485#ifndef __sparc64__ 3486 sc_vtb_init(&scp->scr, VTB_FRAMEBUFFER, scp->xsize, scp->ysize, 3487 (void *)scp->sc->adp->va_window, FALSE); 3488#endif 3489 3490#ifndef SC_NO_FONT_LOADING 3491 /* load appropriate font */ 3492 if (!(scp->status & GRAPHICS_MODE)) { 3493 if (!(scp->status & PIXEL_MODE) && ISFONTAVAIL(scp->sc->adp->va_flags)) { 3494 if (scp->font_size < 14) { 3495 if (scp->sc->fonts_loaded & FONT_8) 3496 sc_load_font(scp, 0, 8, scp->sc->font_8, 0, 256); 3497 } else if (scp->font_size >= 16) { 3498 if (scp->sc->fonts_loaded & FONT_16) 3499 sc_load_font(scp, 0, 16, scp->sc->font_16, 0, 256); 3500 } else { 3501 if (scp->sc->fonts_loaded & FONT_14) 3502 sc_load_font(scp, 0, 14, scp->sc->font_14, 0, 256); 3503 } 3504 /* 3505 * FONT KLUDGE: 3506 * This is an interim kludge to display correct font. 3507 * Always use the font page #0 on the video plane 2. 3508 * Somehow we cannot show the font in other font pages on 3509 * some video cards... XXX 3510 */ 3511 sc_show_font(scp, 0); 3512 } 3513 mark_all(scp); 3514 } 3515#endif /* !SC_NO_FONT_LOADING */ 3516 3517 sc_set_border(scp, scp->border); 3518 sc_set_cursor_image(scp); 3519 3520 return 0; 3521} 3522 3523void 3524sc_set_border(scr_stat *scp, int color) 3525{ 3526 ++scp->sc->videoio_in_progress; 3527 (*scp->rndr->draw_border)(scp, color); 3528 --scp->sc->videoio_in_progress; 3529} 3530 3531#ifndef SC_NO_FONT_LOADING 3532void 3533sc_load_font(scr_stat *scp, int page, int size, u_char *buf, 3534 int base, int count) 3535{ 3536 sc_softc_t *sc; 3537 3538 sc = scp->sc; 3539 sc->font_loading_in_progress = TRUE; 3540 (*vidsw[sc->adapter]->load_font)(sc->adp, page, size, buf, base, count); 3541 sc->font_loading_in_progress = FALSE; 3542} 3543 3544void 3545sc_save_font(scr_stat *scp, int page, int size, u_char *buf, 3546 int base, int count) 3547{ 3548 sc_softc_t *sc; 3549 3550 sc = scp->sc; 3551 sc->font_loading_in_progress = TRUE; 3552 (*vidsw[sc->adapter]->save_font)(sc->adp, page, size, buf, base, count); 3553 sc->font_loading_in_progress = FALSE; 3554} 3555 3556void 3557sc_show_font(scr_stat *scp, int page) 3558{ 3559 (*vidsw[scp->sc->adapter]->show_font)(scp->sc->adp, page); 3560} 3561#endif /* !SC_NO_FONT_LOADING */ 3562 3563void 3564sc_paste(scr_stat *scp, u_char *p, int count) 3565{ 3566 struct tty *tp; 3567 u_char *rmap; 3568 3569 tp = VIRTUAL_TTY(scp->sc, scp->sc->cur_scp->index); 3570 if (!ISTTYOPEN(tp)) 3571 return; 3572 rmap = scp->sc->scr_rmap; 3573 for (; count > 0; --count) 3574 ttyld_rint(tp, rmap[*p++]); 3575} 3576 3577void 3578sc_bell(scr_stat *scp, int pitch, int duration) 3579{ 3580 if (cold || shutdown_in_progress || !enable_bell) 3581 return; 3582 3583 if (scp != scp->sc->cur_scp && (scp->sc->flags & SC_QUIET_BELL)) 3584 return; 3585 3586 if (scp->sc->flags & SC_VISUAL_BELL) { 3587 if (scp->sc->blink_in_progress) 3588 return; 3589 scp->sc->blink_in_progress = 3; 3590 if (scp != scp->sc->cur_scp) 3591 scp->sc->blink_in_progress += 2; 3592 blink_screen(scp->sc->cur_scp); 3593 } else if (duration != 0 && pitch != 0) { 3594 if (scp != scp->sc->cur_scp) 3595 pitch *= 2; 3596 sysbeep(pitch, duration); 3597 } 3598} 3599 3600static void 3601blink_screen(void *arg) 3602{ 3603 scr_stat *scp = arg; 3604 struct tty *tp; 3605 3606 if (ISGRAPHSC(scp) || (scp->sc->blink_in_progress <= 1)) { 3607 scp->sc->blink_in_progress = 0; 3608 mark_all(scp); 3609 tp = VIRTUAL_TTY(scp->sc, scp->index); 3610 if (ISTTYOPEN(tp)) 3611 scstart(tp); 3612 if (scp->sc->delayed_next_scr) 3613 sc_switch_scr(scp->sc, scp->sc->delayed_next_scr - 1); 3614 } 3615 else { 3616 (*scp->rndr->draw)(scp, 0, scp->xsize*scp->ysize, 3617 scp->sc->blink_in_progress & 1); 3618 scp->sc->blink_in_progress--; 3619 timeout(blink_screen, scp, hz / 10); 3620 } 3621} 3622 3623/* 3624 * Until sc_attach_unit() gets called no dev structures will be available 3625 * to store the per-screen current status. This is the case when the 3626 * kernel is initially booting and needs access to its console. During 3627 * this early phase of booting the console's current status is kept in 3628 * one statically defined scr_stat structure, and any pointers to the 3629 * dev structures will be NULL. 3630 */ 3631 3632static scr_stat * 3633sc_get_stat(struct cdev *devptr) 3634{ 3635 if (devptr == NULL) 3636 return (&main_console); 3637 return (SC_STAT(devptr)); 3638}
|