Home | History | Annotate | Line # | Download | only in dev
kd.c revision 1.6
      1  1.6  thorpej /*	$NetBSD: kd.c,v 1.6 2000/03/06 21:36:11 thorpej Exp $	*/
      2  1.1      gwr 
      3  1.1      gwr /*-
      4  1.1      gwr  * Copyright (c) 1996 The NetBSD Foundation, Inc.
      5  1.1      gwr  * All rights reserved.
      6  1.1      gwr  *
      7  1.1      gwr  * This code is derived from software contributed to The NetBSD Foundation
      8  1.1      gwr  * by Gordon W. Ross.
      9  1.1      gwr  *
     10  1.1      gwr  * Redistribution and use in source and binary forms, with or without
     11  1.1      gwr  * modification, are permitted provided that the following conditions
     12  1.1      gwr  * are met:
     13  1.1      gwr  * 1. Redistributions of source code must retain the above copyright
     14  1.1      gwr  *    notice, this list of conditions and the following disclaimer.
     15  1.1      gwr  * 2. Redistributions in binary form must reproduce the above copyright
     16  1.1      gwr  *    notice, this list of conditions and the following disclaimer in the
     17  1.1      gwr  *    documentation and/or other materials provided with the distribution.
     18  1.1      gwr  * 3. All advertising materials mentioning features or use of this software
     19  1.1      gwr  *    must display the following acknowledgement:
     20  1.1      gwr  *        This product includes software developed by the NetBSD
     21  1.1      gwr  *        Foundation, Inc. and its contributors.
     22  1.1      gwr  * 4. Neither the name of The NetBSD Foundation nor the names of its
     23  1.1      gwr  *    contributors may be used to endorse or promote products derived
     24  1.1      gwr  *    from this software without specific prior written permission.
     25  1.1      gwr  *
     26  1.1      gwr  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
     27  1.1      gwr  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
     28  1.1      gwr  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     29  1.1      gwr  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
     30  1.1      gwr  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     31  1.1      gwr  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     32  1.1      gwr  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     33  1.1      gwr  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
     34  1.1      gwr  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     35  1.1      gwr  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     36  1.1      gwr  * POSSIBILITY OF SUCH DAMAGE.
     37  1.1      gwr  */
     38  1.1      gwr 
     39  1.1      gwr /*
     40  1.1      gwr  * Keyboard/Display device.
     41  1.1      gwr  *
     42  1.1      gwr  * This driver exists simply to provide a tty device that
     43  1.1      gwr  * the indirect console driver can point to.
     44  1.1      gwr  * The kbd driver sends its input here.
     45  1.1      gwr  * Output goes to the screen via PROM printf.
     46  1.1      gwr  */
     47  1.1      gwr 
     48  1.1      gwr #include <sys/param.h>
     49  1.1      gwr #include <sys/proc.h>
     50  1.1      gwr #include <sys/systm.h>
     51  1.1      gwr #include <sys/ioctl.h>
     52  1.1      gwr #include <sys/tty.h>
     53  1.1      gwr #include <sys/file.h>
     54  1.1      gwr #include <sys/conf.h>
     55  1.1      gwr #include <sys/device.h>
     56  1.1      gwr 
     57  1.1      gwr #include <machine/bsd_openprom.h>
     58  1.4       pk #include <machine/promlib.h>
     59  1.1      gwr #include <machine/eeprom.h>
     60  1.1      gwr #include <machine/psl.h>
     61  1.1      gwr #include <machine/cpu.h>
     62  1.1      gwr #include <machine/kbd.h>
     63  1.1      gwr #include <machine/autoconf.h>
     64  1.1      gwr #include <machine/conf.h>
     65  1.1      gwr 
     66  1.1      gwr #ifdef RASTERCONSOLE
     67  1.1      gwr #include <machine/fbio.h>
     68  1.1      gwr #include <machine/fbvar.h>
     69  1.1      gwr #endif
     70  1.1      gwr 
     71  1.1      gwr 
     72  1.1      gwr #include <dev/cons.h>
     73  1.1      gwr #include <dev/sun/kbd_xlate.h>
     74  1.1      gwr #include <sparc/dev/cons.h>
     75  1.1      gwr 
     76  1.1      gwr struct	tty *fbconstty = 0;	/* tty structure for frame buffer console */
     77  1.2   mjacob int cnrom __P((void));
     78  1.2   mjacob void cnrint __P((void));
     79  1.1      gwr 
     80  1.1      gwr #define	KDMAJOR 1
     81  1.1      gwr #define PUT_WSIZE	64
     82  1.1      gwr 
     83  1.1      gwr struct kd_softc {
     84  1.1      gwr 	struct	device kd_dev;		/* required first: base device */
     85  1.1      gwr 	struct  tty *kd_tty;
     86  1.1      gwr 	int rows, cols;
     87  1.1      gwr };
     88  1.1      gwr 
     89  1.1      gwr /*
     90  1.1      gwr  * There is no point in pretending there might be
     91  1.1      gwr  * more than one keyboard/display device.
     92  1.1      gwr  */
     93  1.1      gwr static struct kd_softc kd_softc;
     94  1.1      gwr static int kd_is_console;
     95  1.1      gwr 
     96  1.1      gwr static int kdparam(struct tty *, struct termios *);
     97  1.1      gwr static void kdstart(struct tty *);
     98  1.1      gwr 
     99  1.1      gwr int	rom_console_input;	/* when set, hardclock calls cnrom() */
    100  1.1      gwr int	cons_ocount;		/* output byte count */
    101  1.1      gwr 
    102  1.1      gwr /* Now talking directly to the zs, so this is not needed. */
    103  1.1      gwr int
    104  1.1      gwr cnrom()
    105  1.1      gwr {
    106  1.1      gwr   return (0);
    107  1.1      gwr }
    108  1.1      gwr void
    109  1.1      gwr cnrint()
    110  1.1      gwr {
    111  1.1      gwr }
    112  1.1      gwr 
    113  1.1      gwr /*
    114  1.1      gwr  * This is called by kbd_attach()
    115  1.1      gwr  * XXX - Make this a proper child of kbd?
    116  1.1      gwr  */
    117  1.1      gwr void
    118  1.1      gwr kd_init(unit)
    119  1.1      gwr 	int unit;
    120  1.1      gwr {
    121  1.1      gwr 	struct kd_softc *kd;
    122  1.1      gwr 	struct tty *tp;
    123  1.1      gwr 
    124  1.1      gwr 	if (unit != 0)
    125  1.1      gwr 		return;
    126  1.1      gwr 	kd = &kd_softc; 	/* XXX */
    127  1.1      gwr 
    128  1.1      gwr 	tp = ttymalloc();
    129  1.1      gwr 	tp->t_oproc = kdstart;
    130  1.1      gwr 	tp->t_param = kdparam;
    131  1.1      gwr 	tp->t_dev = makedev(KDMAJOR, unit);
    132  1.1      gwr 
    133  1.1      gwr #if 1	/* XXX - Why? */
    134  1.1      gwr 	clalloc(&tp->t_rawq, 1024, 1);
    135  1.1      gwr 	clalloc(&tp->t_canq, 1024, 1);
    136  1.1      gwr 	/* output queue doesn't need quoting */
    137  1.1      gwr 	clalloc(&tp->t_outq, 1024, 0);
    138  1.1      gwr #endif
    139  1.1      gwr 
    140  1.1      gwr 	tty_attach(tp);
    141  1.1      gwr 	kd->kd_tty = tp;
    142  1.1      gwr 
    143  1.1      gwr 	/*
    144  1.1      gwr 	 * get the console struct winsize.
    145  1.1      gwr 	 */
    146  1.1      gwr 	if (kd_is_console) {
    147  1.1      gwr 		fbconstty = tp;
    148  1.1      gwr #ifdef RASTERCONSOLE
    149  1.1      gwr 		kd->rows = fbrcons_rows();
    150  1.1      gwr 		kd->cols = fbrcons_cols();
    151  1.1      gwr #endif
    152  1.1      gwr 	}
    153  1.1      gwr 
    154  1.1      gwr 	if (CPU_ISSUN4COR4M) {
    155  1.1      gwr 		int i;
    156  1.1      gwr 		char *prop;
    157  1.1      gwr 
    158  1.1      gwr 		if (kd->rows == 0 &&
    159  1.1      gwr 		    (prop = getpropstring(optionsnode, "screen-#rows"))) {
    160  1.1      gwr 			i = 0;
    161  1.1      gwr 			while (*prop != '\0')
    162  1.1      gwr 				i = i * 10 + *prop++ - '0';
    163  1.1      gwr 			kd->rows = (unsigned short)i;
    164  1.1      gwr 		}
    165  1.1      gwr 		if (kd->cols == 0 &&
    166  1.1      gwr 		    (prop = getpropstring(optionsnode, "screen-#columns"))) {
    167  1.1      gwr 			i = 0;
    168  1.1      gwr 			while (*prop != '\0')
    169  1.1      gwr 				i = i * 10 + *prop++ - '0';
    170  1.1      gwr 			kd->cols = (unsigned short)i;
    171  1.1      gwr 		}
    172  1.1      gwr 	}
    173  1.1      gwr 	if (CPU_ISSUN4) {
    174  1.1      gwr 		struct eeprom *ep = (struct eeprom *)eeprom_va;
    175  1.1      gwr 
    176  1.1      gwr 		if (ep) {
    177  1.1      gwr 			if (kd->rows == 0)
    178  1.1      gwr 				kd->rows = (u_short)ep->eeTtyRows;
    179  1.1      gwr 			if (kd->cols == 0)
    180  1.1      gwr 				kd->cols = (u_short)ep->eeTtyCols;
    181  1.1      gwr 		}
    182  1.1      gwr 	}
    183  1.1      gwr 
    184  1.1      gwr 	return;
    185  1.1      gwr }
    186  1.1      gwr 
    187  1.1      gwr struct tty *
    188  1.1      gwr kdtty(dev)
    189  1.1      gwr 	dev_t dev;
    190  1.1      gwr {
    191  1.1      gwr 	struct kd_softc *kd;
    192  1.1      gwr 
    193  1.1      gwr 	kd = &kd_softc; 	/* XXX */
    194  1.1      gwr 	return (kd->kd_tty);
    195  1.1      gwr }
    196  1.1      gwr 
    197  1.1      gwr int
    198  1.1      gwr kdopen(dev, flag, mode, p)
    199  1.1      gwr 	dev_t dev;
    200  1.1      gwr 	int flag, mode;
    201  1.1      gwr 	struct proc *p;
    202  1.1      gwr {
    203  1.1      gwr 	struct kd_softc *kd;
    204  1.1      gwr 	int error, s, unit;
    205  1.1      gwr 	struct tty *tp;
    206  1.1      gwr 
    207  1.1      gwr 	unit = minor(dev);
    208  1.1      gwr 	if (unit != 0)
    209  1.1      gwr 		return ENXIO;
    210  1.1      gwr 	kd = &kd_softc; 	/* XXX */
    211  1.1      gwr 	tp = kd->kd_tty;
    212  1.1      gwr 
    213  1.1      gwr 	if ((error = kbd_iopen(unit)) != 0) {
    214  1.1      gwr #ifdef	DIAGNOSTIC
    215  1.1      gwr 		printf("kd: kbd_iopen, error=%d\n", error);
    216  1.1      gwr #endif
    217  1.1      gwr 		return (error);
    218  1.1      gwr 	}
    219  1.1      gwr 
    220  1.1      gwr 	/* It's simpler to do this up here. */
    221  1.1      gwr 	if (((tp->t_state & (TS_ISOPEN | TS_XCLUDE))
    222  1.1      gwr 	     ==             (TS_ISOPEN | TS_XCLUDE))
    223  1.1      gwr 	    && (p->p_ucred->cr_uid != 0) )
    224  1.1      gwr 	{
    225  1.1      gwr 		return (EBUSY);
    226  1.1      gwr 	}
    227  1.1      gwr 
    228  1.1      gwr 	s = spltty();
    229  1.1      gwr 
    230  1.1      gwr 	if ((tp->t_state & TS_ISOPEN) == 0) {
    231  1.1      gwr 		/* First open. */
    232  1.1      gwr 		ttychars(tp);
    233  1.1      gwr 		tp->t_iflag = TTYDEF_IFLAG;
    234  1.1      gwr 		tp->t_oflag = TTYDEF_OFLAG;
    235  1.1      gwr 		tp->t_cflag = TTYDEF_CFLAG;
    236  1.1      gwr 		tp->t_lflag = TTYDEF_LFLAG;
    237  1.1      gwr 		tp->t_ispeed = tp->t_ospeed = TTYDEF_SPEED;
    238  1.1      gwr 		(void) kdparam(tp, &tp->t_termios);
    239  1.1      gwr 		ttsetwater(tp);
    240  1.1      gwr 		tp->t_winsize.ws_row = kd->rows;
    241  1.1      gwr 		tp->t_winsize.ws_col = kd->cols;
    242  1.1      gwr 		/* Flush pending input?  Clear translator? */
    243  1.1      gwr 		/* This (pseudo)device always has SOFTCAR */
    244  1.1      gwr 		tp->t_state |= TS_CARR_ON;
    245  1.1      gwr 	}
    246  1.1      gwr 
    247  1.1      gwr 	splx(s);
    248  1.1      gwr 
    249  1.1      gwr 	return ((*linesw[tp->t_line].l_open)(dev, tp));
    250  1.1      gwr }
    251  1.1      gwr 
    252  1.1      gwr int
    253  1.1      gwr kdclose(dev, flag, mode, p)
    254  1.1      gwr 	dev_t dev;
    255  1.1      gwr 	int flag, mode;
    256  1.1      gwr 	struct proc *p;
    257  1.1      gwr {
    258  1.1      gwr 	struct kd_softc *kd;
    259  1.1      gwr 	struct tty *tp;
    260  1.1      gwr 
    261  1.1      gwr 	kd = &kd_softc; 	/* XXX */
    262  1.1      gwr 	tp = kd->kd_tty;
    263  1.1      gwr 
    264  1.1      gwr 	/* XXX This is for cons.c. */
    265  1.1      gwr 	if ((tp->t_state & TS_ISOPEN) == 0)
    266  1.1      gwr 		return 0;
    267  1.1      gwr 
    268  1.1      gwr 	(*linesw[tp->t_line].l_close)(tp, flag);
    269  1.1      gwr 	ttyclose(tp);
    270  1.1      gwr 	return (0);
    271  1.1      gwr }
    272  1.1      gwr 
    273  1.1      gwr int
    274  1.1      gwr kdread(dev, uio, flag)
    275  1.1      gwr 	dev_t dev;
    276  1.1      gwr 	struct uio *uio;
    277  1.1      gwr 	int flag;
    278  1.1      gwr {
    279  1.1      gwr 	struct kd_softc *kd;
    280  1.1      gwr 	struct tty *tp;
    281  1.1      gwr 
    282  1.1      gwr 	kd = &kd_softc; 	/* XXX */
    283  1.1      gwr 	tp = kd->kd_tty;
    284  1.1      gwr 
    285  1.1      gwr 	return ((*linesw[tp->t_line].l_read)(tp, uio, flag));
    286  1.1      gwr }
    287  1.1      gwr 
    288  1.1      gwr int
    289  1.1      gwr kdwrite(dev, uio, flag)
    290  1.1      gwr 	dev_t dev;
    291  1.1      gwr 	struct uio *uio;
    292  1.1      gwr 	int flag;
    293  1.1      gwr {
    294  1.1      gwr 	struct kd_softc *kd;
    295  1.1      gwr 	struct tty *tp;
    296  1.1      gwr 
    297  1.1      gwr 	kd = &kd_softc; 	/* XXX */
    298  1.1      gwr 	tp = kd->kd_tty;
    299  1.1      gwr 
    300  1.1      gwr 	return ((*linesw[tp->t_line].l_write)(tp, uio, flag));
    301  1.1      gwr }
    302  1.1      gwr 
    303  1.1      gwr int
    304  1.1      gwr kdioctl(dev, cmd, data, flag, p)
    305  1.1      gwr 	dev_t dev;
    306  1.1      gwr 	u_long cmd;
    307  1.1      gwr 	caddr_t data;
    308  1.1      gwr 	int flag;
    309  1.1      gwr 	struct proc *p;
    310  1.1      gwr {
    311  1.1      gwr 	struct kd_softc *kd;
    312  1.1      gwr 	struct tty *tp;
    313  1.1      gwr 	int error;
    314  1.1      gwr 
    315  1.1      gwr 	kd = &kd_softc; 	/* XXX */
    316  1.1      gwr 	tp = kd->kd_tty;
    317  1.1      gwr 
    318  1.1      gwr 	error = (*linesw[tp->t_line].l_ioctl)(tp, cmd, data, flag, p);
    319  1.1      gwr 	if (error >= 0)
    320  1.1      gwr 		return error;
    321  1.1      gwr 	error = ttioctl(tp, cmd, data, flag, p);
    322  1.1      gwr 	if (error >= 0)
    323  1.1      gwr 		return error;
    324  1.1      gwr 
    325  1.1      gwr 	/* Handle any ioctl commands specific to kbd/display. */
    326  1.1      gwr 	/* XXX - Send KB* ioctls to kbd module? */
    327  1.1      gwr 	/* XXX - Send FB* ioctls to fb module?  */
    328  1.1      gwr 
    329  1.1      gwr 	return ENOTTY;
    330  1.1      gwr }
    331  1.1      gwr 
    332  1.1      gwr void
    333  1.1      gwr kdstop(tp, flag)
    334  1.1      gwr 	struct tty *tp;
    335  1.1      gwr 	int flag;
    336  1.1      gwr {
    337  1.1      gwr 
    338  1.1      gwr }
    339  1.1      gwr 
    340  1.1      gwr 
    341  1.1      gwr static int
    342  1.1      gwr kdparam(tp, t)
    343  1.1      gwr 	struct tty *tp;
    344  1.1      gwr 	struct termios *t;
    345  1.1      gwr {
    346  1.1      gwr 	/* XXX - These are ignored... */
    347  1.1      gwr 	tp->t_ispeed = t->c_ispeed;
    348  1.1      gwr 	tp->t_ospeed = t->c_ospeed;
    349  1.1      gwr 	tp->t_cflag = t->c_cflag;
    350  1.1      gwr 	return 0;
    351  1.1      gwr }
    352  1.1      gwr 
    353  1.1      gwr 
    354  1.1      gwr static void kd_later(void*);
    355  1.1      gwr static void kd_putfb(struct tty *);
    356  1.1      gwr 
    357  1.1      gwr static void
    358  1.1      gwr kdstart(tp)
    359  1.1      gwr 	struct tty *tp;
    360  1.1      gwr {
    361  1.1      gwr 	struct clist *cl;
    362  1.1      gwr 	register int s;
    363  1.1      gwr 
    364  1.1      gwr 	s = spltty();
    365  1.1      gwr 	if (tp->t_state & (TS_BUSY|TS_TTSTOP|TS_TIMEOUT))
    366  1.1      gwr 		goto out;
    367  1.1      gwr 
    368  1.1      gwr 	cl = &tp->t_outq;
    369  1.1      gwr 	if (cl->c_cc) {
    370  1.1      gwr 		if (kd_is_console) {
    371  1.1      gwr 			tp->t_state |= TS_BUSY;
    372  1.1      gwr 			if ((s & PSR_PIL) == 0) {
    373  1.1      gwr 				/* called at level zero - update screen now. */
    374  1.5  thorpej 				(void) spllowersoftclock();
    375  1.1      gwr 				kd_putfb(tp);
    376  1.1      gwr 				(void) spltty();
    377  1.1      gwr 				tp->t_state &= ~TS_BUSY;
    378  1.1      gwr 			} else {
    379  1.1      gwr 				/* called at interrupt level - do it later */
    380  1.1      gwr 				timeout(kd_later, (void*)tp, 0);
    381  1.1      gwr 			}
    382  1.1      gwr 		} else {
    383  1.1      gwr 			/*
    384  1.1      gwr 			 * This driver uses the PROM for writing the screen,
    385  1.1      gwr 			 * and that only works if this is the console device.
    386  1.1      gwr 			 * If this is not the console, just flush the output.
    387  1.1      gwr 			 * Sorry.  (In that case, use xdm instead of getty.)
    388  1.1      gwr 			 */
    389  1.1      gwr 			ndflush(cl, cl->c_cc);
    390  1.1      gwr 		}
    391  1.1      gwr 	}
    392  1.1      gwr 	if (cl->c_cc <= tp->t_lowat) {
    393  1.1      gwr 		if (tp->t_state & TS_ASLEEP) {
    394  1.1      gwr 			tp->t_state &= ~TS_ASLEEP;
    395  1.1      gwr 			wakeup((caddr_t)cl);
    396  1.1      gwr 		}
    397  1.1      gwr 		selwakeup(&tp->t_wsel);
    398  1.1      gwr 	}
    399  1.1      gwr out:
    400  1.1      gwr 	splx(s);
    401  1.1      gwr }
    402  1.1      gwr 
    403  1.1      gwr /*
    404  1.1      gwr  * Timeout function to do delayed writes to the screen.
    405  1.1      gwr  * Called at splsoftclock when requested by kdstart.
    406  1.1      gwr  */
    407  1.1      gwr static void
    408  1.1      gwr kd_later(tpaddr)
    409  1.1      gwr 	void *tpaddr;
    410  1.1      gwr {
    411  1.1      gwr 	struct tty *tp = tpaddr;
    412  1.1      gwr 	register int s;
    413  1.1      gwr 
    414  1.1      gwr 	kd_putfb(tp);
    415  1.1      gwr 
    416  1.1      gwr 	s = spltty();
    417  1.1      gwr 	tp->t_state &= ~TS_BUSY;
    418  1.1      gwr 	(*linesw[tp->t_line].l_start)(tp);
    419  1.1      gwr 	splx(s);
    420  1.1      gwr }
    421  1.1      gwr 
    422  1.1      gwr /*
    423  1.1      gwr  * Put text on the screen using the PROM monitor.
    424  1.1      gwr  * This can take a while, so to avoid missing
    425  1.1      gwr  * interrupts, this is called at splsoftclock.
    426  1.1      gwr  */
    427  1.1      gwr static void
    428  1.1      gwr kd_putfb(tp)
    429  1.1      gwr 	struct tty *tp;
    430  1.1      gwr {
    431  1.1      gwr 	char buf[PUT_WSIZE];
    432  1.1      gwr 	struct clist *cl = &tp->t_outq;
    433  1.1      gwr 	char *p, *end;
    434  1.1      gwr 	int len;
    435  1.1      gwr 
    436  1.1      gwr 	while ((len = q_to_b(cl, buf, PUT_WSIZE-1)) > 0) {
    437  1.1      gwr 		/* PROM will barf if high bits are set. */
    438  1.1      gwr 		p = buf;
    439  1.1      gwr 		end = buf + len;
    440  1.1      gwr 		while (p < end)
    441  1.1      gwr 			*p++ &= 0x7f;
    442  1.4       pk 
    443  1.1      gwr 		/* Now let the PROM print it. */
    444  1.4       pk 		prom_putstr(buf, len);
    445  1.1      gwr 	}
    446  1.1      gwr }
    447  1.1      gwr 
    448  1.1      gwr /*
    449  1.1      gwr  * Our "interrupt" routine for input. This is called by
    450  1.1      gwr  * the keyboard driver (dev/sun/kbd.c) at spltty.
    451  1.1      gwr  */
    452  1.1      gwr void
    453  1.1      gwr kd_input(c)
    454  1.1      gwr 	int c;
    455  1.1      gwr {
    456  1.1      gwr 	struct kd_softc *kd = &kd_softc;
    457  1.1      gwr 	struct tty *tp;
    458  1.1      gwr 
    459  1.1      gwr 	/* XXX: Make sure the device is open. */
    460  1.1      gwr 	tp = kd->kd_tty;
    461  1.1      gwr 	if (tp == NULL)
    462  1.1      gwr 		return;
    463  1.1      gwr 	if ((tp->t_state & TS_ISOPEN) == 0)
    464  1.1      gwr 		return;
    465  1.1      gwr 
    466  1.1      gwr 	(*linesw[tp->t_line].l_rint)(c, tp);
    467  1.1      gwr }
    468  1.1      gwr 
    469  1.1      gwr 
    470  1.1      gwr /****************************************************************
    471  1.1      gwr  * kd console support
    472  1.1      gwr  ****************************************************************/
    473  1.1      gwr 
    474  1.1      gwr /* The debugger gets its own key translation state. */
    475  1.1      gwr static struct kbd_state kdcn_state;
    476  1.1      gwr 
    477  1.1      gwr static void kdcnprobe __P((struct consdev *));
    478  1.1      gwr static void kdcninit __P((struct consdev *));
    479  1.1      gwr static int  kdcngetc __P((dev_t));
    480  1.1      gwr static void kdcnputc __P((dev_t, int));
    481  1.1      gwr static void kdcnpollc __P((dev_t, int));
    482  1.1      gwr 
    483  1.1      gwr struct consdev consdev_kd = {
    484  1.1      gwr 	kdcnprobe,
    485  1.1      gwr 	kdcninit,
    486  1.1      gwr 	kdcngetc,
    487  1.1      gwr 	kdcnputc,
    488  1.1      gwr 	kdcnpollc,
    489  1.6  thorpej 	NULL,
    490  1.1      gwr };
    491  1.1      gwr 
    492  1.1      gwr /* We never call this. */
    493  1.1      gwr static void
    494  1.1      gwr kdcnprobe(cn)
    495  1.1      gwr 	struct consdev *cn;
    496  1.1      gwr {
    497  1.1      gwr }
    498  1.1      gwr 
    499  1.1      gwr static void
    500  1.1      gwr kdcninit(cn)
    501  1.1      gwr 	struct consdev *cn;
    502  1.1      gwr {
    503  1.1      gwr 	struct kbd_state *ks = &kdcn_state;
    504  1.1      gwr 
    505  1.1      gwr 	cn->cn_dev = makedev(KDMAJOR, 0);
    506  1.1      gwr 	cn->cn_pri = CN_INTERNAL;
    507  1.1      gwr 
    508  1.1      gwr 	/* This prepares kbd_translate() */
    509  1.1      gwr 	ks->kbd_id = KBD_MIN_TYPE;
    510  1.1      gwr 	kbd_xlate_init(ks);
    511  1.1      gwr 
    512  1.1      gwr 	/* Indicate that it is OK to use the PROM fbwrite */
    513  1.1      gwr 	kd_is_console = 1;
    514  1.1      gwr }
    515  1.1      gwr 
    516  1.1      gwr static int
    517  1.1      gwr kdcngetc(dev)
    518  1.1      gwr 	dev_t dev;
    519  1.1      gwr {
    520  1.1      gwr 	struct kbd_state *ks = &kdcn_state;
    521  1.1      gwr 	int code, class, data, keysym;
    522  1.1      gwr 
    523  1.1      gwr 	for (;;) {
    524  1.1      gwr 		code = zs_getc(zs_conschan);
    525  1.1      gwr 		keysym = kbd_code_to_keysym(ks, code);
    526  1.1      gwr 		class = KEYSYM_CLASS(keysym);
    527  1.1      gwr 
    528  1.1      gwr 		switch (class) {
    529  1.1      gwr 		case KEYSYM_ASCII:
    530  1.1      gwr 			goto out;
    531  1.1      gwr 
    532  1.1      gwr 		case KEYSYM_CLRMOD:
    533  1.1      gwr 		case KEYSYM_SETMOD:
    534  1.1      gwr 			data = (keysym & 0x1F);
    535  1.1      gwr 			/* Only allow ctrl or shift. */
    536  1.1      gwr 			if (data > KBMOD_SHIFT_R)
    537  1.1      gwr 				break;
    538  1.1      gwr 			data = 1 << data;
    539  1.1      gwr 			if (class == KEYSYM_SETMOD)
    540  1.1      gwr 				ks->kbd_modbits |= data;
    541  1.1      gwr 			else
    542  1.1      gwr 				ks->kbd_modbits &= ~data;
    543  1.1      gwr 			break;
    544  1.1      gwr 
    545  1.1      gwr 		case KEYSYM_ALL_UP:
    546  1.1      gwr 			/* No toggle keys here. */
    547  1.1      gwr 			ks->kbd_modbits = 0;
    548  1.1      gwr 			break;
    549  1.1      gwr 
    550  1.1      gwr 		default:	/* ignore all other keysyms */
    551  1.1      gwr 			break;
    552  1.1      gwr 		}
    553  1.1      gwr 	}
    554  1.1      gwr out:
    555  1.1      gwr 	return (keysym);
    556  1.1      gwr }
    557  1.1      gwr 
    558  1.1      gwr static void
    559  1.1      gwr kdcnputc(dev, c)
    560  1.1      gwr 	dev_t dev;
    561  1.1      gwr 	int c;
    562  1.1      gwr {
    563  1.1      gwr 
    564  1.4       pk 	prom_putchar(c);
    565  1.1      gwr }
    566  1.1      gwr 
    567  1.1      gwr static void
    568  1.1      gwr kdcnpollc(dev, on)
    569  1.1      gwr 	dev_t dev;
    570  1.1      gwr 	int on;
    571  1.1      gwr {
    572  1.1      gwr 	struct kbd_state *ks = &kdcn_state;
    573  1.1      gwr 
    574  1.1      gwr 	if (on) {
    575  1.1      gwr 		/* Entering debugger. */
    576  1.3      mrg #if NFB > 0
    577  1.1      gwr 		fb_unblank();
    578  1.3      mrg #endif
    579  1.1      gwr 		/* Clear shift keys too. */
    580  1.1      gwr 		ks->kbd_modbits = 0;
    581  1.1      gwr 	} else {
    582  1.1      gwr 		/* Resuming kernel. */
    583  1.1      gwr 	}
    584  1.1      gwr }
    585  1.1      gwr 
    586