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