ite.c revision 1.21 1 1.21 tsutsui /* $NetBSD: ite.c,v 1.21 2025/05/26 12:25:12 tsutsui Exp $ */
2 1.1 thorpej
3 1.1 thorpej /*
4 1.11 rmind * Copyright (c) 1988 University of Utah.
5 1.1 thorpej * Copyright (c) 1990, 1993
6 1.1 thorpej * The Regents of the University of California. All rights reserved.
7 1.2 agc *
8 1.2 agc * This code is derived from software contributed to Berkeley by
9 1.2 agc * the Systems Programming Group of the University of Utah Computer
10 1.2 agc * Science Department.
11 1.2 agc *
12 1.2 agc * Redistribution and use in source and binary forms, with or without
13 1.2 agc * modification, are permitted provided that the following conditions
14 1.2 agc * are met:
15 1.2 agc * 1. Redistributions of source code must retain the above copyright
16 1.2 agc * notice, this list of conditions and the following disclaimer.
17 1.2 agc * 2. Redistributions in binary form must reproduce the above copyright
18 1.2 agc * notice, this list of conditions and the following disclaimer in the
19 1.2 agc * documentation and/or other materials provided with the distribution.
20 1.2 agc * 3. Neither the name of the University nor the names of its contributors
21 1.2 agc * may be used to endorse or promote products derived from this software
22 1.2 agc * without specific prior written permission.
23 1.2 agc *
24 1.2 agc * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
25 1.2 agc * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
26 1.2 agc * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
27 1.2 agc * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
28 1.2 agc * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
29 1.2 agc * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
30 1.2 agc * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
31 1.2 agc * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
32 1.2 agc * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
33 1.2 agc * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
34 1.2 agc * SUCH DAMAGE.
35 1.2 agc *
36 1.2 agc * from: Utah $Hdr: ite.c 1.24 93/06/25$
37 1.2 agc *
38 1.2 agc * @(#)ite.c 8.1 (Berkeley) 7/8/93
39 1.2 agc */
40 1.1 thorpej
41 1.1 thorpej /*
42 1.1 thorpej * Standalone Internal Terminal Emulator (CRT and keyboard)
43 1.1 thorpej */
44 1.1 thorpej
45 1.1 thorpej #ifdef ITECONSOLE
46 1.1 thorpej
47 1.1 thorpej #include <sys/param.h>
48 1.1 thorpej #include <dev/cons.h>
49 1.1 thorpej
50 1.19 tsutsui #include <hp300/dev/diofbreg.h>
51 1.7 tsutsui #include <hp300/dev/intioreg.h>
52 1.21 tsutsui #include <hp300/dev/dioreg.h>
53 1.17 tsutsui #include <hp300/dev/sgcreg.h>
54 1.17 tsutsui #include <dev/ic/stireg.h>
55 1.1 thorpej
56 1.1 thorpej #include <hp300/stand/common/device.h>
57 1.1 thorpej #include <hp300/stand/common/itevar.h>
58 1.3 tsutsui #include <hp300/stand/common/kbdvar.h>
59 1.1 thorpej #include <hp300/stand/common/consdefs.h>
60 1.1 thorpej #include <hp300/stand/common/samachdep.h>
61 1.1 thorpej
62 1.3 tsutsui static void iteconfig(void);
63 1.3 tsutsui static void ite_clrtoeol(struct ite_data *, struct itesw *, int, int);
64 1.3 tsutsui static void itecheckwrap(struct ite_data *, struct itesw *);
65 1.1 thorpej
66 1.17 tsutsui #define GID_STI 0x100 /* any value which is not a DIO fb, really */
67 1.17 tsutsui
68 1.1 thorpej struct itesw itesw[] = {
69 1.21 tsutsui {
70 1.21 tsutsui .ite_hwid = GID_TOPCAT,
71 1.21 tsutsui .ite_probe = NULL,
72 1.21 tsutsui .ite_init = topcat_init,
73 1.21 tsutsui .ite_clear = ite_dio_clear,
74 1.21 tsutsui .ite_putc = ite_dio_putc8bpp,
75 1.21 tsutsui .ite_cursor = ite_dio_cursor,
76 1.21 tsutsui .ite_scroll = ite_dio_scroll
77 1.21 tsutsui },
78 1.21 tsutsui
79 1.21 tsutsui {
80 1.21 tsutsui .ite_hwid = GID_GATORBOX,
81 1.21 tsutsui .ite_probe = NULL,
82 1.21 tsutsui .ite_init = gbox_init,
83 1.21 tsutsui .ite_clear = ite_dio_clear,
84 1.21 tsutsui .ite_putc = ite_dio_putc8bpp,
85 1.21 tsutsui .ite_cursor = ite_dio_cursor,
86 1.21 tsutsui .ite_scroll = gbox_scroll
87 1.21 tsutsui },
88 1.21 tsutsui
89 1.21 tsutsui {
90 1.21 tsutsui .ite_hwid = GID_RENAISSANCE,
91 1.21 tsutsui .ite_probe = NULL,
92 1.21 tsutsui .ite_init = rbox_init,
93 1.21 tsutsui .ite_clear = ite_dio_clear,
94 1.21 tsutsui .ite_putc = ite_dio_putc8bpp,
95 1.21 tsutsui .ite_cursor = ite_dio_cursor,
96 1.21 tsutsui .ite_scroll = ite_dio_scroll
97 1.21 tsutsui },
98 1.21 tsutsui
99 1.21 tsutsui {
100 1.21 tsutsui .ite_hwid = GID_LRCATSEYE,
101 1.21 tsutsui .ite_probe = NULL,
102 1.21 tsutsui .ite_init = topcat_init,
103 1.21 tsutsui .ite_clear = ite_dio_clear,
104 1.21 tsutsui .ite_putc = ite_dio_putc8bpp,
105 1.21 tsutsui .ite_cursor = ite_dio_cursor,
106 1.21 tsutsui .ite_scroll = ite_dio_scroll
107 1.21 tsutsui },
108 1.21 tsutsui
109 1.21 tsutsui {
110 1.21 tsutsui .ite_hwid = GID_HRCCATSEYE,
111 1.21 tsutsui .ite_probe = NULL,
112 1.21 tsutsui .ite_init = topcat_init,
113 1.21 tsutsui .ite_clear = ite_dio_clear,
114 1.21 tsutsui .ite_putc = ite_dio_putc8bpp,
115 1.21 tsutsui .ite_cursor = ite_dio_cursor,
116 1.21 tsutsui .ite_scroll = ite_dio_scroll
117 1.21 tsutsui },
118 1.21 tsutsui
119 1.21 tsutsui {
120 1.21 tsutsui .ite_hwid = GID_HRMCATSEYE,
121 1.21 tsutsui .ite_probe = NULL,
122 1.21 tsutsui .ite_init = topcat_init,
123 1.21 tsutsui .ite_clear = ite_dio_clear,
124 1.21 tsutsui .ite_putc = ite_dio_putc8bpp,
125 1.21 tsutsui .ite_cursor = ite_dio_cursor,
126 1.21 tsutsui .ite_scroll = ite_dio_scroll
127 1.21 tsutsui },
128 1.21 tsutsui
129 1.21 tsutsui {
130 1.21 tsutsui .ite_hwid = GID_DAVINCI,
131 1.21 tsutsui .ite_probe = NULL,
132 1.21 tsutsui .ite_init = dvbox_init,
133 1.21 tsutsui .ite_clear = ite_dio_clear,
134 1.21 tsutsui .ite_putc = ite_dio_putc8bpp,
135 1.21 tsutsui .ite_cursor = ite_dio_cursor,
136 1.21 tsutsui .ite_scroll = ite_dio_scroll
137 1.21 tsutsui },
138 1.21 tsutsui
139 1.21 tsutsui {
140 1.21 tsutsui .ite_hwid = GID_HYPERION,
141 1.21 tsutsui .ite_probe = NULL,
142 1.21 tsutsui .ite_init = hyper_init,
143 1.21 tsutsui .ite_clear = ite_dio_clear,
144 1.21 tsutsui .ite_putc = ite_dio_putc1bpp,
145 1.21 tsutsui .ite_cursor = ite_dio_cursor,
146 1.21 tsutsui .ite_scroll = ite_dio_scroll
147 1.21 tsutsui },
148 1.21 tsutsui
149 1.21 tsutsui {
150 1.21 tsutsui .ite_hwid = GID_TIGER,
151 1.21 tsutsui .ite_probe = NULL,
152 1.21 tsutsui .ite_init = tvrx_init,
153 1.21 tsutsui .ite_clear = ite_dio_clear,
154 1.21 tsutsui .ite_putc = ite_dio_putc1bpp,
155 1.21 tsutsui .ite_cursor = ite_dio_cursor,
156 1.21 tsutsui .ite_scroll = ite_dio_scroll
157 1.21 tsutsui },
158 1.21 tsutsui
159 1.21 tsutsui {
160 1.21 tsutsui .ite_hwid = GID_A1474MID,
161 1.21 tsutsui .ite_probe = sti_dio_probe,
162 1.21 tsutsui .ite_init = sti_iteinit_dio,
163 1.21 tsutsui .ite_clear = sti_clear,
164 1.21 tsutsui .ite_putc = sti_putc,
165 1.21 tsutsui .ite_cursor = sti_cursor,
166 1.21 tsutsui .ite_scroll = sti_scroll
167 1.21 tsutsui },
168 1.21 tsutsui
169 1.21 tsutsui {
170 1.21 tsutsui .ite_hwid = GID_A147xVGA,
171 1.21 tsutsui .ite_probe = sti_dio_probe,
172 1.21 tsutsui .ite_init = sti_iteinit_dio,
173 1.21 tsutsui .ite_clear = sti_clear,
174 1.21 tsutsui .ite_putc = sti_putc,
175 1.21 tsutsui .ite_cursor = sti_cursor,
176 1.21 tsutsui .ite_scroll = sti_scroll
177 1.21 tsutsui },
178 1.21 tsutsui
179 1.21 tsutsui {
180 1.21 tsutsui .ite_hwid = GID_STI,
181 1.21 tsutsui .ite_probe = NULL,
182 1.21 tsutsui .ite_init = sti_iteinit_sgc,
183 1.21 tsutsui .ite_clear = sti_clear,
184 1.21 tsutsui .ite_putc = sti_putc,
185 1.21 tsutsui .ite_cursor = sti_cursor,
186 1.21 tsutsui .ite_scroll = sti_scroll
187 1.21 tsutsui },
188 1.1 thorpej };
189 1.1 thorpej
190 1.1 thorpej /* these guys need to be in initialized data */
191 1.1 thorpej int itecons = -1;
192 1.3 tsutsui struct ite_data ite_data[NITE] = { { 0 } };
193 1.1 thorpej
194 1.1 thorpej /*
195 1.1 thorpej * Locate all bitmapped displays
196 1.1 thorpej */
197 1.3 tsutsui static void
198 1.4 tsutsui iteconfig(void)
199 1.1 thorpej {
200 1.17 tsutsui int dtype, fboff, slotno, i;
201 1.17 tsutsui uint8_t *va;
202 1.1 thorpej struct hp_hw *hw;
203 1.19 tsutsui struct diofbreg *fb;
204 1.1 thorpej struct ite_data *ip;
205 1.1 thorpej
206 1.1 thorpej i = 0;
207 1.1 thorpej for (hw = sc_table; hw < &sc_table[MAXCTLRS]; hw++) {
208 1.1 thorpej if (!HW_ISDEV(hw, D_BITMAP))
209 1.1 thorpej continue;
210 1.19 tsutsui fb = (struct diofbreg *)hw->hw_kva;
211 1.1 thorpej /* XXX: redundent but safe */
212 1.19 tsutsui if (badaddr((void *)fb) || fb->id != GRFHWID)
213 1.1 thorpej continue;
214 1.21 tsutsui for (dtype = 0; dtype < __arraycount(itesw); dtype++)
215 1.19 tsutsui if (itesw[dtype].ite_hwid == fb->fbid)
216 1.1 thorpej break;
217 1.21 tsutsui if (dtype == __arraycount(itesw))
218 1.1 thorpej continue;
219 1.1 thorpej if (i >= NITE)
220 1.1 thorpej break;
221 1.1 thorpej ip = &ite_data[i];
222 1.21 tsutsui ip->scode = hw->hw_sc;
223 1.1 thorpej ip->isw = &itesw[dtype];
224 1.19 tsutsui ip->regbase = (void *)fb;
225 1.19 tsutsui fboff = (fb->fbomsb << 8) | fb->fbolsb;
226 1.8 christos ip->fbbase = (void *)(*((u_char *)ip->regbase + fboff) << 16);
227 1.1 thorpej /* DIO II: FB offset is relative to select code space */
228 1.21 tsutsui if (DIO_ISDIOII(ip->scode))
229 1.21 tsutsui ip->fbbase = (uint8_t *)ip->fbbase + (int)ip->regbase;
230 1.19 tsutsui ip->fbwidth = fb->fbwmsb << 8 | fb->fbwlsb;
231 1.19 tsutsui ip->fbheight = fb->fbhmsb << 8 | fb->fbhlsb;
232 1.19 tsutsui ip->dwidth = fb->dwmsb << 8 | fb->dwlsb;
233 1.19 tsutsui ip->dheight = fb->dhmsb << 8 | fb->dhlsb;
234 1.1 thorpej /*
235 1.1 thorpej * XXX some displays (e.g. the davinci) appear
236 1.1 thorpej * to return a display height greater than the
237 1.1 thorpej * returned FB height. Guess we should go back
238 1.1 thorpej * to getting the display dimensions from the
239 1.1 thorpej * fontrom...
240 1.1 thorpej */
241 1.1 thorpej if (ip->dwidth > ip->fbwidth)
242 1.1 thorpej ip->dwidth = ip->fbwidth;
243 1.1 thorpej if (ip->dheight > ip->fbheight)
244 1.1 thorpej ip->dheight = ip->fbheight;
245 1.21 tsutsui /* confirm hardware is what we think it is */
246 1.21 tsutsui if (itesw[dtype].ite_probe != NULL &&
247 1.21 tsutsui (*itesw[dtype].ite_probe)(ip) != 0)
248 1.21 tsutsui continue;
249 1.14 tsutsui ip->alive = 1;
250 1.1 thorpej i++;
251 1.1 thorpej }
252 1.17 tsutsui
253 1.17 tsutsui /*
254 1.17 tsutsui * Now probe for SGC frame buffers.
255 1.17 tsutsui */
256 1.17 tsutsui switch (machineid) {
257 1.17 tsutsui case HP_400:
258 1.17 tsutsui case HP_425:
259 1.17 tsutsui case HP_433:
260 1.17 tsutsui break;
261 1.17 tsutsui default:
262 1.17 tsutsui return;
263 1.17 tsutsui }
264 1.17 tsutsui
265 1.17 tsutsui /* SGC frame buffers can only be STI... */
266 1.21 tsutsui for (dtype = 0; dtype < __arraycount(itesw); dtype++)
267 1.17 tsutsui if (itesw[dtype].ite_hwid == GID_STI)
268 1.17 tsutsui break;
269 1.17 tsutsui if (dtype == __arraycount(itesw))
270 1.17 tsutsui return;
271 1.17 tsutsui
272 1.17 tsutsui for (slotno = 0; slotno < SGC_NSLOTS; slotno++) {
273 1.17 tsutsui va = (uint8_t *)IIOV(SGC_BASE + (slotno * SGC_DEVSIZE));
274 1.17 tsutsui
275 1.17 tsutsui /* Check to see if hardware exists. */
276 1.17 tsutsui if (badaddr(va) != 0)
277 1.17 tsutsui continue;
278 1.17 tsutsui
279 1.17 tsutsui /* Check hardware. */
280 1.17 tsutsui if (va[3] == STI_DEVTYPE1) {
281 1.17 tsutsui if (i >= NITE)
282 1.17 tsutsui break;
283 1.17 tsutsui ip = &ite_data[i];
284 1.17 tsutsui ip->scode = slotno;
285 1.17 tsutsui ip->isw = &itesw[dtype];
286 1.17 tsutsui /* to get CN_MIDPRI */
287 1.17 tsutsui ip->regbase = (uint8_t *)(INTIOBASE + FB_BASE);
288 1.17 tsutsui /* ...and do not need an ite_probe() check */
289 1.17 tsutsui ip->alive = 1;
290 1.17 tsutsui i++;
291 1.17 tsutsui /* we only support one SGC frame buffer at the moment */
292 1.17 tsutsui break;
293 1.17 tsutsui }
294 1.17 tsutsui }
295 1.1 thorpej }
296 1.1 thorpej
297 1.1 thorpej #ifdef CONSDEBUG
298 1.1 thorpej /*
299 1.1 thorpej * Allows us to cycle through all possible consoles (NITE ites and serial port)
300 1.1 thorpej * by using SHIFT-RESET on the keyboard.
301 1.1 thorpej */
302 1.1 thorpej int whichconsole = -1;
303 1.1 thorpej #endif
304 1.1 thorpej
305 1.1 thorpej void
306 1.4 tsutsui iteprobe(struct consdev *cp)
307 1.1 thorpej {
308 1.3 tsutsui int ite;
309 1.3 tsutsui struct ite_data *ip;
310 1.1 thorpej int unit, pri;
311 1.1 thorpej
312 1.1 thorpej #ifdef CONSDEBUG
313 1.18 christos whichconsole = (whichconsole + 1) % (NITE+1);
314 1.1 thorpej #endif
315 1.1 thorpej
316 1.1 thorpej if (itecons != -1)
317 1.1 thorpej return;
318 1.1 thorpej
319 1.1 thorpej iteconfig();
320 1.1 thorpej unit = -1;
321 1.1 thorpej pri = CN_DEAD;
322 1.1 thorpej for (ite = 0; ite < NITE; ite++) {
323 1.1 thorpej #ifdef CONSDEBUG
324 1.1 thorpej if (ite < whichconsole)
325 1.1 thorpej continue;
326 1.1 thorpej #endif
327 1.1 thorpej ip = &ite_data[ite];
328 1.14 tsutsui if (ip->alive == 0)
329 1.1 thorpej continue;
330 1.7 tsutsui if ((int)ip->regbase == INTIOBASE + FB_BASE) {
331 1.1 thorpej pri = CN_INTERNAL;
332 1.1 thorpej unit = ite;
333 1.1 thorpej } else if (unit < 0) {
334 1.1 thorpej pri = CN_NORMAL;
335 1.1 thorpej unit = ite;
336 1.1 thorpej }
337 1.1 thorpej }
338 1.21 tsutsui ip = &ite_data[unit];
339 1.21 tsutsui curcons_scode = ip->scode;
340 1.1 thorpej cp->cn_dev = unit;
341 1.1 thorpej cp->cn_pri = pri;
342 1.1 thorpej }
343 1.1 thorpej
344 1.1 thorpej void
345 1.4 tsutsui iteinit(struct consdev *cp)
346 1.1 thorpej {
347 1.1 thorpej int ite = cp->cn_dev;
348 1.1 thorpej struct ite_data *ip;
349 1.1 thorpej
350 1.1 thorpej if (itecons != -1)
351 1.1 thorpej return;
352 1.1 thorpej
353 1.1 thorpej ip = &ite_data[ite];
354 1.1 thorpej
355 1.1 thorpej ip->curx = 0;
356 1.1 thorpej ip->cury = 0;
357 1.1 thorpej ip->cursorx = 0;
358 1.1 thorpej ip->cursory = 0;
359 1.1 thorpej
360 1.1 thorpej (*ip->isw->ite_init)(ip);
361 1.1 thorpej (*ip->isw->ite_cursor)(ip, DRAW_CURSOR);
362 1.1 thorpej
363 1.1 thorpej itecons = ite;
364 1.1 thorpej kbdinit();
365 1.1 thorpej }
366 1.1 thorpej
367 1.1 thorpej void
368 1.4 tsutsui iteputchar(dev_t dev, int c)
369 1.1 thorpej {
370 1.3 tsutsui struct ite_data *ip = &ite_data[itecons];
371 1.3 tsutsui struct itesw *sp = ip->isw;
372 1.1 thorpej
373 1.1 thorpej c &= 0x7F;
374 1.1 thorpej switch (c) {
375 1.1 thorpej
376 1.1 thorpej case '\n':
377 1.1 thorpej if (++ip->cury == ip->rows) {
378 1.1 thorpej ip->cury--;
379 1.14 tsutsui (*sp->ite_scroll)(ip);
380 1.1 thorpej ite_clrtoeol(ip, sp, ip->cury, 0);
381 1.1 thorpej }
382 1.1 thorpej else
383 1.1 thorpej (*sp->ite_cursor)(ip, MOVE_CURSOR);
384 1.1 thorpej break;
385 1.1 thorpej
386 1.1 thorpej case '\r':
387 1.1 thorpej ip->curx = 0;
388 1.1 thorpej (*sp->ite_cursor)(ip, MOVE_CURSOR);
389 1.1 thorpej break;
390 1.1 thorpej
391 1.1 thorpej case '\b':
392 1.1 thorpej if (--ip->curx < 0)
393 1.1 thorpej ip->curx = 0;
394 1.1 thorpej else
395 1.1 thorpej (*sp->ite_cursor)(ip, MOVE_CURSOR);
396 1.1 thorpej break;
397 1.1 thorpej
398 1.1 thorpej default:
399 1.1 thorpej if (c < ' ' || c == 0177)
400 1.1 thorpej break;
401 1.14 tsutsui (*sp->ite_putc)(ip, c, ip->cury, ip->curx);
402 1.1 thorpej (*sp->ite_cursor)(ip, DRAW_CURSOR);
403 1.1 thorpej itecheckwrap(ip, sp);
404 1.1 thorpej break;
405 1.1 thorpej }
406 1.1 thorpej }
407 1.1 thorpej
408 1.3 tsutsui static void
409 1.4 tsutsui itecheckwrap(struct ite_data *ip, struct itesw *sp)
410 1.1 thorpej {
411 1.1 thorpej if (++ip->curx == ip->cols) {
412 1.1 thorpej ip->curx = 0;
413 1.1 thorpej if (++ip->cury == ip->rows) {
414 1.1 thorpej --ip->cury;
415 1.14 tsutsui (*sp->ite_scroll)(ip);
416 1.1 thorpej ite_clrtoeol(ip, sp, ip->cury, 0);
417 1.1 thorpej return;
418 1.1 thorpej }
419 1.1 thorpej }
420 1.1 thorpej (*sp->ite_cursor)(ip, MOVE_CURSOR);
421 1.1 thorpej }
422 1.1 thorpej
423 1.3 tsutsui static void
424 1.4 tsutsui ite_clrtoeol(struct ite_data *ip, struct itesw *sp, int y, int x)
425 1.1 thorpej {
426 1.4 tsutsui
427 1.1 thorpej (*sp->ite_clear)(ip, y, x, 1, ip->cols - x);
428 1.1 thorpej (*sp->ite_cursor)(ip, DRAW_CURSOR);
429 1.1 thorpej }
430 1.1 thorpej
431 1.1 thorpej int
432 1.4 tsutsui itegetchar(dev_t dev)
433 1.1 thorpej {
434 1.3 tsutsui
435 1.1 thorpej #ifdef SMALL
436 1.3 tsutsui return 0;
437 1.1 thorpej #else
438 1.3 tsutsui return kbdgetc();
439 1.1 thorpej #endif
440 1.1 thorpej }
441 1.1 thorpej #endif
442