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