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