Home | History | Annotate | Line # | Download | only in rcons
rcons_kern.c revision 1.1
      1  1.1  pk /*	$NetBSD: rcons_kern.c,v 1.1 1995/09/17 19:56:40 pk Exp $ */
      2  1.1  pk 
      3  1.1  pk /*
      4  1.1  pk  * Copyright (c) 1991, 1993
      5  1.1  pk  *	The Regents of the University of California.  All rights reserved.
      6  1.1  pk  *
      7  1.1  pk  * This software was developed by the Computer Systems Engineering group
      8  1.1  pk  * at Lawrence Berkeley Laboratory under DARPA contract BG 91-66 and
      9  1.1  pk  * contributed to Berkeley.
     10  1.1  pk  *
     11  1.1  pk  * All advertising materials mentioning features or use of this software
     12  1.1  pk  * must display the following acknowledgement:
     13  1.1  pk  *	This product includes software developed by the University of
     14  1.1  pk  *	California, Lawrence Berkeley Laboratory.
     15  1.1  pk  *
     16  1.1  pk  * Redistribution and use in source and binary forms, with or without
     17  1.1  pk  * modification, are permitted provided that the following conditions
     18  1.1  pk  * are met:
     19  1.1  pk  * 1. Redistributions of source code must retain the above copyright
     20  1.1  pk  *    notice, this list of conditions and the following disclaimer.
     21  1.1  pk  * 2. Redistributions in binary form must reproduce the above copyright
     22  1.1  pk  *    notice, this list of conditions and the following disclaimer in the
     23  1.1  pk  *    documentation and/or other materials provided with the distribution.
     24  1.1  pk  * 3. All advertising materials mentioning features or use of this software
     25  1.1  pk  *    must display the following acknowledgement:
     26  1.1  pk  *	This product includes software developed by the University of
     27  1.1  pk  *	California, Berkeley and its contributors.
     28  1.1  pk  * 4. Neither the name of the University nor the names of its contributors
     29  1.1  pk  *    may be used to endorse or promote products derived from this software
     30  1.1  pk  *    without specific prior written permission.
     31  1.1  pk  *
     32  1.1  pk  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
     33  1.1  pk  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
     34  1.1  pk  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
     35  1.1  pk  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
     36  1.1  pk  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
     37  1.1  pk  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
     38  1.1  pk  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     39  1.1  pk  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
     40  1.1  pk  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
     41  1.1  pk  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
     42  1.1  pk  * SUCH DAMAGE.
     43  1.1  pk  *
     44  1.1  pk  *	@(#)rcons_kern.c	8.1 (Berkeley) 6/11/93
     45  1.1  pk  */
     46  1.1  pk 
     47  1.1  pk #include <sys/param.h>
     48  1.1  pk #include <sys/device.h>
     49  1.1  pk #include <sys/kernel.h>
     50  1.1  pk #include <sys/systm.h>
     51  1.1  pk #include <sys/ioctl.h>
     52  1.1  pk #include <sys/tty.h>
     53  1.1  pk #include <dev/rcons/raster.h>
     54  1.1  pk #include <dev/rcons/rcons.h>
     55  1.1  pk 
     56  1.1  pk extern struct tty *fbconstty;
     57  1.1  pk 
     58  1.1  pk static void rcons_belltmr(void *);
     59  1.1  pk 
     60  1.1  pk extern void rcons_puts(struct rconsole *, char *, int);
     61  1.1  pk extern void rcons_font(struct rconsole *);
     62  1.1  pk 
     63  1.1  pk static struct rconsole *mydevicep;
     64  1.1  pk 
     65  1.1  pk void
     66  1.1  pk rcons_cnputc(c)
     67  1.1  pk 	int c;
     68  1.1  pk {
     69  1.1  pk 	char buf[1];
     70  1.1  pk 
     71  1.1  pk 	if (c == '\n')
     72  1.1  pk 		rcons_puts(mydevicep, "\r\n", 2);
     73  1.1  pk 	else {
     74  1.1  pk 		buf[0] = c;
     75  1.1  pk 		rcons_puts(mydevicep, buf, 1);
     76  1.1  pk 	}
     77  1.1  pk }
     78  1.1  pk 
     79  1.1  pk static void
     80  1.1  pk rcons_output(tp)
     81  1.1  pk 	register struct tty *tp;
     82  1.1  pk {
     83  1.1  pk 	register int s, n, i;
     84  1.1  pk 	char buf[OBUFSIZ];
     85  1.1  pk 
     86  1.1  pk 	s = spltty();
     87  1.1  pk 	if (tp->t_state & (TS_TIMEOUT | TS_BUSY | TS_TTSTOP)) {
     88  1.1  pk 		splx(s);
     89  1.1  pk 		return;
     90  1.1  pk 	}
     91  1.1  pk 	tp->t_state |= TS_BUSY;
     92  1.1  pk 	splx(s);
     93  1.1  pk 	n = q_to_b(&tp->t_outq, buf, sizeof(buf));
     94  1.1  pk 	for (i = 0; i < n; ++i)
     95  1.1  pk 		buf[i] &= 0177;		/* strip parity (argh) */
     96  1.1  pk 	rcons_puts(mydevicep, buf, n);
     97  1.1  pk 
     98  1.1  pk 	s = spltty();
     99  1.1  pk 	tp->t_state &= ~TS_BUSY;
    100  1.1  pk 	/* Come back if there's more to do */
    101  1.1  pk 	if (tp->t_outq.c_cc) {
    102  1.1  pk 		tp->t_state |= TS_TIMEOUT;
    103  1.1  pk 		timeout(ttrstrt, tp, 1);
    104  1.1  pk 	}
    105  1.1  pk 	if (tp->t_outq.c_cc <= tp->t_lowat) {
    106  1.1  pk 		if (tp->t_state&TS_ASLEEP) {
    107  1.1  pk 			tp->t_state &= ~TS_ASLEEP;
    108  1.1  pk 			wakeup((caddr_t)&tp->t_outq);
    109  1.1  pk 		}
    110  1.1  pk 		selwakeup(&tp->t_wsel);
    111  1.1  pk 	}
    112  1.1  pk 	splx(s);
    113  1.1  pk }
    114  1.1  pk 
    115  1.1  pk /* Ring the console bell */
    116  1.1  pk void
    117  1.1  pk rcons_bell(rc)
    118  1.1  pk 	register struct rconsole *rc;
    119  1.1  pk {
    120  1.1  pk 	register int i, s;
    121  1.1  pk 
    122  1.1  pk 	if (rc->rc_bits & FB_VISBELL) {
    123  1.1  pk 		/* invert the screen twice */
    124  1.1  pk 		for (i = 0; i < 2; ++i)
    125  1.1  pk 			raster_op(rc->rc_sp, 0, 0,
    126  1.1  pk 			    rc->rc_sp->width, rc->rc_sp->height,
    127  1.1  pk 			    RAS_INVERT, (struct raster *) 0, 0, 0);
    128  1.1  pk 	}
    129  1.1  pk 
    130  1.1  pk 	s = splhigh();
    131  1.1  pk 	if (rc->rc_belldepth++) {
    132  1.1  pk 		if (rc->rc_belldepth > 3)
    133  1.1  pk 			rc->rc_belldepth = 3;
    134  1.1  pk 		splx(s);
    135  1.1  pk 	} else {
    136  1.1  pk 		rc->rc_ringing = 1;
    137  1.1  pk 		splx(s);
    138  1.1  pk 		(*rc->rc_bell)(1);
    139  1.1  pk 		/* XXX Chris doesn't like the following divide */
    140  1.1  pk 		timeout(rcons_belltmr, rc, hz/10);
    141  1.1  pk 	}
    142  1.1  pk }
    143  1.1  pk 
    144  1.1  pk /* Bell timer service routine */
    145  1.1  pk static void
    146  1.1  pk rcons_belltmr(p)
    147  1.1  pk 	void *p;
    148  1.1  pk {
    149  1.1  pk 	register struct rconsole *rc = p;
    150  1.1  pk 	register int s = splhigh(), i;
    151  1.1  pk 
    152  1.1  pk 	if (rc->rc_ringing) {
    153  1.1  pk 		rc->rc_ringing = 0;
    154  1.1  pk 		i = --rc->rc_belldepth;
    155  1.1  pk 		splx(s);
    156  1.1  pk 		(*rc->rc_bell)(0);
    157  1.1  pk 		if (i != 0)
    158  1.1  pk 			/* XXX Chris doesn't like the following divide */
    159  1.1  pk 			timeout(rcons_belltmr, rc, hz/30);
    160  1.1  pk 	} else {
    161  1.1  pk 		rc->rc_ringing = 1;
    162  1.1  pk 		splx(s);
    163  1.1  pk 		(*rc->rc_bell)(1);
    164  1.1  pk 		timeout(rcons_belltmr, rc, hz/10);
    165  1.1  pk 	}
    166  1.1  pk }
    167  1.1  pk 
    168  1.1  pk void
    169  1.1  pk rcons_init(rc)
    170  1.1  pk 	register struct rconsole *rc;
    171  1.1  pk {
    172  1.1  pk 	/* XXX this should go away */
    173  1.1  pk 	static struct raster xxxraster;
    174  1.1  pk 	register struct raster *rp = rc->rc_sp = &xxxraster;
    175  1.1  pk 	register struct winsize *ws;
    176  1.1  pk 	register int i;
    177  1.1  pk 	static int row, col;
    178  1.1  pk 
    179  1.1  pk 	mydevicep = rc;
    180  1.1  pk 
    181  1.1  pk 	/* XXX mostly duplicates of data in other places */
    182  1.1  pk 	rp->width = rc->rc_width;
    183  1.1  pk 	rp->height = rc->rc_height;
    184  1.1  pk 	rp->depth = rc->rc_depth;
    185  1.1  pk 	if (rc->rc_linebytes & 0x3) {
    186  1.1  pk 		printf("rcons_init: linebytes assumption botched (0x%x)\n",
    187  1.1  pk 		    rc->rc_linebytes);
    188  1.1  pk 		return;
    189  1.1  pk 	}
    190  1.1  pk 	rp->linelongs = rc->rc_linebytes >> 2;
    191  1.1  pk 	rp->pixels = (u_long *)rc->rc_pixels;
    192  1.1  pk 
    193  1.1  pk 	rc->rc_ras_blank = RAS_CLEAR;
    194  1.1  pk 
    195  1.1  pk 	/* Setup the static font */
    196  1.1  pk 	rcons_font(rc);
    197  1.1  pk 
    198  1.1  pk 	/* Impose upper bounds on rc_max{row,col} */
    199  1.1  pk 	i = rc->rc_height / rc->rc_font->height;
    200  1.1  pk 	if (rc->rc_maxrow > i)
    201  1.1  pk 		rc->rc_maxrow = i;
    202  1.1  pk 	i = rc->rc_width / rc->rc_font->width;
    203  1.1  pk 	if (rc->rc_maxcol > i)
    204  1.1  pk 		rc->rc_maxcol = i;
    205  1.1  pk 
    206  1.1  pk 	/* Let the system know how big the console is */
    207  1.1  pk 	ws = &fbconstty->t_winsize;
    208  1.1  pk 	ws->ws_row = rc->rc_maxrow;
    209  1.1  pk 	ws->ws_col = rc->rc_maxcol;
    210  1.1  pk 	ws->ws_xpixel = rc->rc_width;
    211  1.1  pk 	ws->ws_ypixel = rc->rc_height;
    212  1.1  pk 
    213  1.1  pk 	/* Center emulator screen (but align x origin to 32 bits) */
    214  1.1  pk 	rc->rc_xorigin =
    215  1.1  pk 	    ((rc->rc_width - rc->rc_maxcol * rc->rc_font->width) / 2) & ~0x1f;
    216  1.1  pk 	rc->rc_yorigin =
    217  1.1  pk 	    (rc->rc_height - rc->rc_maxrow * rc->rc_font->height) / 2;
    218  1.1  pk 
    219  1.1  pk 	/* Emulator width and height used for scrolling */
    220  1.1  pk 	rc->rc_emuwidth = rc->rc_maxcol * rc->rc_font->width;
    221  1.1  pk 	if (rc->rc_emuwidth & 0x1f) {
    222  1.1  pk 		/* Pad to 32 bits */
    223  1.1  pk 		i = (rc->rc_emuwidth + 0x1f) & ~0x1f;
    224  1.1  pk 		/* Make sure emulator width isn't too wide */
    225  1.1  pk 		if (rc->rc_xorigin + i <= rc->rc_width)
    226  1.1  pk 			rc->rc_emuwidth = i;
    227  1.1  pk 	}
    228  1.1  pk 	rc->rc_emuheight = rc->rc_maxrow * rc->rc_font->height;
    229  1.1  pk 
    230  1.1  pk 	if (rc->rc_row == NULL || rc->rc_col == NULL) {
    231  1.1  pk 		/* No address passed; use private copies */
    232  1.1  pk 		rc->rc_row = &row;
    233  1.1  pk 		rc->rc_col = &col;
    234  1.1  pk 		row = col = 0;
    235  1.1  pk 		rcons_clear2eop(rc);	/* clear the display */
    236  1.1  pk 		rcons_cursor(rc);	/* and draw the initial cursor */
    237  1.1  pk 	} else {
    238  1.1  pk 		/* Prom emulator cursor is currently visible */
    239  1.1  pk 		rc->rc_bits |= FB_CURSOR;
    240  1.1  pk 	}
    241  1.1  pk 
    242  1.1  pk 	/* Initialization done; hook us up */
    243  1.1  pk 	fbconstty->t_oproc = rcons_output;
    244  1.1  pk 	/*fbconstty->t_stop = (void (*)()) nullop;*/
    245  1.1  pk }
    246