rcons_kern.c revision 1.5 1 /* $NetBSD: rcons_kern.c,v 1.5 1996/10/10 21:19:55 christos 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 <sys/proc.h>
54 #include <dev/rcons/raster.h>
55 #include <dev/rcons/rcons.h>
56
57 extern struct tty *fbconstty;
58
59 static void rcons_belltmr(void *);
60
61 #include "rcons_subr.h"
62
63 static struct rconsole *mydevicep;
64 static void rcons_output __P((struct tty *));
65
66 void
67 rcons_cnputc(c)
68 int c;
69 {
70 char buf[1];
71
72 if (c == '\n')
73 rcons_puts(mydevicep, "\r\n", 2);
74 else {
75 buf[0] = c;
76 rcons_puts(mydevicep, buf, 1);
77 }
78 }
79
80 static void
81 rcons_output(tp)
82 register struct tty *tp;
83 {
84 register int s, n;
85 char buf[OBUFSIZ];
86
87 s = spltty();
88 if (tp->t_state & (TS_TIMEOUT | TS_BUSY | TS_TTSTOP)) {
89 splx(s);
90 return;
91 }
92 tp->t_state |= TS_BUSY;
93 splx(s);
94 n = q_to_b(&tp->t_outq, buf, sizeof(buf));
95 rcons_puts(mydevicep, buf, n);
96
97 s = spltty();
98 tp->t_state &= ~TS_BUSY;
99 /* Come back if there's more to do */
100 if (tp->t_outq.c_cc) {
101 tp->t_state |= TS_TIMEOUT;
102 timeout(ttrstrt, tp, 1);
103 }
104 if (tp->t_outq.c_cc <= tp->t_lowat) {
105 if (tp->t_state&TS_ASLEEP) {
106 tp->t_state &= ~TS_ASLEEP;
107 wakeup((caddr_t)&tp->t_outq);
108 }
109 selwakeup(&tp->t_wsel);
110 }
111 splx(s);
112 }
113
114 /* Ring the console bell */
115 void
116 rcons_bell(rc)
117 register struct rconsole *rc;
118 {
119 register int i, s;
120
121 if (rc->rc_bits & FB_VISBELL) {
122 /* invert the screen twice */
123 for (i = 0; i < 2; ++i)
124 raster_op(rc->rc_sp, 0, 0,
125 rc->rc_sp->width, rc->rc_sp->height,
126 RAS_INVERT, (struct raster *) 0, 0, 0);
127 }
128
129 s = splhigh();
130 if (rc->rc_belldepth++) {
131 if (rc->rc_belldepth > 3)
132 rc->rc_belldepth = 3;
133 splx(s);
134 } else {
135 rc->rc_ringing = 1;
136 splx(s);
137 (*rc->rc_bell)(1);
138 /* XXX Chris doesn't like the following divide */
139 timeout(rcons_belltmr, rc, hz/10);
140 }
141 }
142
143 /* Bell timer service routine */
144 static void
145 rcons_belltmr(p)
146 void *p;
147 {
148 register struct rconsole *rc = p;
149 register int s = splhigh(), i;
150
151 if (rc->rc_ringing) {
152 rc->rc_ringing = 0;
153 i = --rc->rc_belldepth;
154 splx(s);
155 (*rc->rc_bell)(0);
156 if (i != 0)
157 /* XXX Chris doesn't like the following divide */
158 timeout(rcons_belltmr, rc, hz/30);
159 } else {
160 rc->rc_ringing = 1;
161 splx(s);
162 (*rc->rc_bell)(1);
163 timeout(rcons_belltmr, rc, hz/10);
164 }
165 }
166
167 void
168 rcons_init(rc)
169 register struct rconsole *rc;
170 {
171 /* XXX this should go away */
172 static struct raster xxxraster;
173 register struct raster *rp = rc->rc_sp = &xxxraster;
174 register struct winsize *ws;
175 register int i;
176 static int row, col;
177
178 mydevicep = rc;
179
180 /* XXX mostly duplicates of data in other places */
181 rp->width = rc->rc_width;
182 rp->height = rc->rc_height;
183 rp->depth = rc->rc_depth;
184 if (rc->rc_linebytes & 0x3) {
185 kprintf("rcons_init: linebytes assumption botched (0x%x)\n",
186 rc->rc_linebytes);
187 return;
188 }
189 rp->linelongs = rc->rc_linebytes >> 2;
190 rp->pixels = (u_int32_t *)rc->rc_pixels;
191
192 rc->rc_ras_blank = RAS_CLEAR;
193
194 /* Impose upper bounds on rc_max{row,col} */
195 i = rc->rc_height / rc->rc_font->height;
196 if (rc->rc_maxrow > i)
197 rc->rc_maxrow = i;
198 i = rc->rc_width / rc->rc_font->width;
199 if (rc->rc_maxcol > i)
200 rc->rc_maxcol = i;
201
202 /* Let the system know how big the console is */
203 ws = &fbconstty->t_winsize;
204 ws->ws_row = rc->rc_maxrow;
205 ws->ws_col = rc->rc_maxcol;
206 ws->ws_xpixel = rc->rc_width;
207 ws->ws_ypixel = rc->rc_height;
208
209 /* Center emulator screen (but align x origin to 32 bits) */
210 rc->rc_xorigin =
211 ((rc->rc_width - rc->rc_maxcol * rc->rc_font->width) / 2) & ~0x1f;
212 rc->rc_yorigin =
213 (rc->rc_height - rc->rc_maxrow * rc->rc_font->height) / 2;
214
215 /* Emulator width and height used for scrolling */
216 rc->rc_emuwidth = rc->rc_maxcol * rc->rc_font->width;
217 if (rc->rc_emuwidth & 0x1f) {
218 /* Pad to 32 bits */
219 i = (rc->rc_emuwidth + 0x1f) & ~0x1f;
220 /* Make sure emulator width isn't too wide */
221 if (rc->rc_xorigin + i <= rc->rc_width)
222 rc->rc_emuwidth = i;
223 }
224 rc->rc_emuheight = rc->rc_maxrow * rc->rc_font->height;
225
226 #ifdef RASTERCONS_WONB
227 rc->rc_ras_blank = RAS_NOT(rc->rc_ras_blank);
228 rc->rc_bits |= FB_INVERT;
229 #endif
230
231 if (rc->rc_row == NULL || rc->rc_col == NULL) {
232 /*
233 * No address passed; use private copies
234 * go to LL corner and scroll.
235 */
236 rc->rc_row = &row;
237 rc->rc_col = &col;
238 row = rc->rc_maxrow;
239 col = 0;
240 #if 0
241 rcons_clear2eop(rc); /* clear the display */
242 #endif
243 rcons_scroll(rc, 1);
244 rcons_cursor(rc); /* and draw the initial cursor */
245 } else {
246 /* Prom emulator cursor is currently visible */
247 rc->rc_bits |= FB_CURSOR;
248 }
249
250 /* Initialization done; hook us up */
251 fbconstty->t_oproc = rcons_output;
252 /*fbconstty->t_stop = (void (*)()) nullop;*/
253 }
254