Home | History | Annotate | Line # | Download | only in common
ite.c revision 1.16.10.1
      1  1.16.10.1    bouyer /*	$NetBSD: ite.c,v 1.16.10.1 2014/05/21 20:56:36 bouyer 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.10   tsutsui #include <hp300/stand/common/grfreg.h>
     51        1.7   tsutsui #include <hp300/dev/intioreg.h>
     52  1.16.10.1    bouyer #include <hp300/dev/sgcreg.h>
     53  1.16.10.1    bouyer #include <dev/ic/stireg.h>
     54        1.1   thorpej 
     55        1.1   thorpej #include <hp300/stand/common/device.h>
     56        1.1   thorpej #include <hp300/stand/common/itevar.h>
     57        1.3   tsutsui #include <hp300/stand/common/kbdvar.h>
     58        1.1   thorpej #include <hp300/stand/common/consdefs.h>
     59        1.1   thorpej #include <hp300/stand/common/samachdep.h>
     60        1.1   thorpej 
     61        1.3   tsutsui static void iteconfig(void);
     62        1.3   tsutsui static void ite_clrtoeol(struct ite_data *, struct itesw *, int, int);
     63        1.3   tsutsui static void itecheckwrap(struct ite_data *, struct itesw *);
     64        1.1   thorpej 
     65  1.16.10.1    bouyer #define GID_STI		0x100	/* any value which is not a DIO fb, really */
     66  1.16.10.1    bouyer 
     67        1.1   thorpej struct itesw itesw[] = {
     68        1.1   thorpej 	{ GID_TOPCAT,
     69       1.14   tsutsui 	topcat_init,	ite_dio_clear,	ite_dio_putc8bpp,
     70       1.14   tsutsui 	ite_dio_cursor,	ite_dio_scroll },
     71        1.1   thorpej 
     72        1.1   thorpej 	{ GID_GATORBOX,
     73       1.14   tsutsui 	gbox_init,	ite_dio_clear,	ite_dio_putc8bpp,
     74       1.14   tsutsui 	ite_dio_cursor,	gbox_scroll },
     75        1.1   thorpej 
     76        1.1   thorpej 	{ GID_RENAISSANCE,
     77       1.14   tsutsui 	rbox_init,	ite_dio_clear,	ite_dio_putc8bpp,
     78       1.14   tsutsui 	ite_dio_cursor,	ite_dio_scroll },
     79        1.1   thorpej 
     80        1.1   thorpej 	{ GID_LRCATSEYE,
     81       1.14   tsutsui 	topcat_init,	ite_dio_clear,	ite_dio_putc8bpp,
     82       1.14   tsutsui 	ite_dio_cursor,	ite_dio_scroll },
     83        1.1   thorpej 
     84        1.1   thorpej 	{ GID_HRCCATSEYE,
     85       1.14   tsutsui 	topcat_init,	ite_dio_clear,	ite_dio_putc8bpp,
     86       1.14   tsutsui 	ite_dio_cursor,	ite_dio_scroll },
     87        1.1   thorpej 
     88        1.1   thorpej 	{ GID_HRMCATSEYE,
     89       1.14   tsutsui 	topcat_init,	ite_dio_clear,	ite_dio_putc8bpp,
     90       1.14   tsutsui 	ite_dio_cursor,	ite_dio_scroll },
     91        1.1   thorpej 
     92        1.1   thorpej 	{ GID_DAVINCI,
     93       1.14   tsutsui       	dvbox_init,	ite_dio_clear,	ite_dio_putc8bpp,
     94       1.14   tsutsui 	ite_dio_cursor,	ite_dio_scroll },
     95        1.1   thorpej 
     96        1.1   thorpej 	{ GID_HYPERION,
     97       1.14   tsutsui 	hyper_init,	ite_dio_clear,	ite_dio_putc1bpp,
     98       1.14   tsutsui 	ite_dio_cursor,	ite_dio_scroll },
     99       1.15   tsutsui 
    100       1.15   tsutsui 	{ GID_TIGER,
    101       1.15   tsutsui 	tvrx_init,	ite_dio_clear,	ite_dio_putc1bpp,
    102       1.15   tsutsui 	ite_dio_cursor,	ite_dio_scroll },
    103       1.16   tsutsui 
    104       1.16   tsutsui 	{ GID_A1474MID,
    105       1.16   tsutsui 	dumb_init,	dumb_clear,	dumb_putc,
    106       1.16   tsutsui 	dumb_cursor,	dumb_scroll },
    107       1.16   tsutsui 
    108       1.16   tsutsui 	{ GID_A147xVGA,
    109       1.16   tsutsui 	dumb_init,	dumb_clear,	dumb_putc,
    110       1.16   tsutsui 	dumb_cursor,	dumb_scroll },
    111  1.16.10.1    bouyer 
    112  1.16.10.1    bouyer 	{ GID_STI,
    113  1.16.10.1    bouyer 	sti_iteinit_sgc, sti_clear,	sti_putc,
    114  1.16.10.1    bouyer 	sti_cursor,	sti_scroll },
    115        1.1   thorpej };
    116        1.1   thorpej int	nitesw = sizeof(itesw) / sizeof(itesw[0]);
    117        1.1   thorpej 
    118        1.1   thorpej /* these guys need to be in initialized data */
    119        1.1   thorpej int itecons = -1;
    120        1.3   tsutsui struct  ite_data ite_data[NITE] = { { 0 } };
    121        1.1   thorpej int	ite_scode[NITE] = { 0 };
    122        1.1   thorpej 
    123        1.1   thorpej /*
    124        1.1   thorpej  * Locate all bitmapped displays
    125        1.1   thorpej  */
    126        1.3   tsutsui static void
    127        1.4   tsutsui iteconfig(void)
    128        1.1   thorpej {
    129  1.16.10.1    bouyer 	int dtype, fboff, slotno, i;
    130  1.16.10.1    bouyer 	uint8_t *va;
    131        1.1   thorpej 	struct hp_hw *hw;
    132        1.1   thorpej 	struct grfreg *gr;
    133        1.1   thorpej 	struct ite_data *ip;
    134        1.1   thorpej 
    135        1.1   thorpej 	i = 0;
    136        1.1   thorpej 	for (hw = sc_table; hw < &sc_table[MAXCTLRS]; hw++) {
    137        1.1   thorpej 	        if (!HW_ISDEV(hw, D_BITMAP))
    138        1.1   thorpej 			continue;
    139        1.1   thorpej 		gr = (struct grfreg *) hw->hw_kva;
    140        1.1   thorpej 		/* XXX: redundent but safe */
    141        1.8  christos 		if (badaddr((void *)gr) || gr->gr_id != GRFHWID)
    142        1.1   thorpej 			continue;
    143        1.1   thorpej 		for (dtype = 0; dtype < nitesw; dtype++)
    144        1.1   thorpej 			if (itesw[dtype].ite_hwid == gr->gr_id2)
    145        1.1   thorpej 				break;
    146        1.1   thorpej 		if (dtype == nitesw)
    147        1.1   thorpej 			continue;
    148        1.1   thorpej 		if (i >= NITE)
    149        1.1   thorpej 			break;
    150        1.1   thorpej 		ite_scode[i] = hw->hw_sc;
    151        1.1   thorpej 		ip = &ite_data[i];
    152        1.1   thorpej 		ip->isw = &itesw[dtype];
    153        1.8  christos 		ip->regbase = (void *) gr;
    154        1.1   thorpej 		fboff = (gr->gr_fbomsb << 8) | gr->gr_fbolsb;
    155        1.8  christos 		ip->fbbase = (void *)(*((u_char *)ip->regbase + fboff) << 16);
    156        1.1   thorpej 		/* DIO II: FB offset is relative to select code space */
    157        1.8  christos 		if (ip->regbase >= (void *)DIOIIBASE)
    158        1.9        he 			ip->fbbase = (char*)ip->fbbase + (int)ip->regbase;
    159        1.1   thorpej 		ip->fbwidth  = gr->gr_fbwidth_h << 8 | gr->gr_fbwidth_l;
    160        1.1   thorpej 		ip->fbheight = gr->gr_fbheight_h << 8 | gr->gr_fbheight_l;
    161        1.1   thorpej 		ip->dwidth   = gr->gr_dwidth_h << 8 | gr->gr_dwidth_l;
    162        1.1   thorpej 		ip->dheight  = gr->gr_dheight_h << 8 | gr->gr_dheight_l;
    163        1.1   thorpej 		/*
    164        1.1   thorpej 		 * XXX some displays (e.g. the davinci) appear
    165        1.1   thorpej 		 * to return a display height greater than the
    166        1.1   thorpej 		 * returned FB height.  Guess we should go back
    167        1.1   thorpej 		 * to getting the display dimensions from the
    168        1.1   thorpej 		 * fontrom...
    169        1.1   thorpej 		 */
    170        1.1   thorpej 		if (ip->dwidth > ip->fbwidth)
    171        1.1   thorpej 			ip->dwidth = ip->fbwidth;
    172        1.1   thorpej 		if (ip->dheight > ip->fbheight)
    173        1.1   thorpej 			ip->dheight = ip->fbheight;
    174       1.14   tsutsui 		ip->alive = 1;
    175        1.1   thorpej 		i++;
    176        1.1   thorpej 	}
    177  1.16.10.1    bouyer 
    178  1.16.10.1    bouyer 	/*
    179  1.16.10.1    bouyer 	 * Now probe for SGC frame buffers.
    180  1.16.10.1    bouyer 	 */
    181  1.16.10.1    bouyer 	switch (machineid) {
    182  1.16.10.1    bouyer 	case HP_400:
    183  1.16.10.1    bouyer 	case HP_425:
    184  1.16.10.1    bouyer 	case HP_433:
    185  1.16.10.1    bouyer 		break;
    186  1.16.10.1    bouyer 	default:
    187  1.16.10.1    bouyer 		return;
    188  1.16.10.1    bouyer 	}
    189  1.16.10.1    bouyer 
    190  1.16.10.1    bouyer 	/* SGC frame buffers can only be STI... */
    191  1.16.10.1    bouyer 	for (dtype = 0; dtype < __arraycount(itesw); dtype++) {
    192  1.16.10.1    bouyer 		if (itesw[dtype].ite_hwid == GID_STI)
    193  1.16.10.1    bouyer 			break;
    194  1.16.10.1    bouyer 	}
    195  1.16.10.1    bouyer 	if (dtype == __arraycount(itesw))
    196  1.16.10.1    bouyer 		return;
    197  1.16.10.1    bouyer 
    198  1.16.10.1    bouyer 	for (slotno = 0; slotno < SGC_NSLOTS; slotno++) {
    199  1.16.10.1    bouyer 		va = (uint8_t *)IIOV(SGC_BASE + (slotno * SGC_DEVSIZE));
    200  1.16.10.1    bouyer 
    201  1.16.10.1    bouyer 		/* Check to see if hardware exists. */
    202  1.16.10.1    bouyer 		if (badaddr(va) != 0)
    203  1.16.10.1    bouyer 			continue;
    204  1.16.10.1    bouyer 
    205  1.16.10.1    bouyer 		/* Check hardware. */
    206  1.16.10.1    bouyer 		if (va[3] == STI_DEVTYPE1) {
    207  1.16.10.1    bouyer 			if (i >= NITE)
    208  1.16.10.1    bouyer 				break;
    209  1.16.10.1    bouyer 			ip = &ite_data[i];
    210  1.16.10.1    bouyer 			ip->scode = slotno;
    211  1.16.10.1    bouyer 			ip->isw = &itesw[dtype];
    212  1.16.10.1    bouyer 			/* to get CN_MIDPRI */
    213  1.16.10.1    bouyer 			ip->regbase = (uint8_t *)(INTIOBASE + FB_BASE);
    214  1.16.10.1    bouyer 			/* ...and do not need an ite_probe() check */
    215  1.16.10.1    bouyer 			ip->alive = 1;
    216  1.16.10.1    bouyer 			i++;
    217  1.16.10.1    bouyer 			/* we only support one SGC frame buffer at the moment */
    218  1.16.10.1    bouyer 			break;
    219  1.16.10.1    bouyer 		}
    220  1.16.10.1    bouyer 	}
    221        1.1   thorpej }
    222        1.1   thorpej 
    223        1.1   thorpej #ifdef CONSDEBUG
    224        1.1   thorpej /*
    225        1.1   thorpej  * Allows us to cycle through all possible consoles (NITE ites and serial port)
    226        1.1   thorpej  * by using SHIFT-RESET on the keyboard.
    227        1.1   thorpej  */
    228        1.1   thorpej int	whichconsole = -1;
    229        1.1   thorpej #endif
    230        1.1   thorpej 
    231        1.1   thorpej void
    232        1.4   tsutsui iteprobe(struct consdev *cp)
    233        1.1   thorpej {
    234        1.3   tsutsui 	int ite;
    235        1.3   tsutsui 	struct ite_data *ip;
    236        1.1   thorpej 	int unit, pri;
    237        1.1   thorpej 
    238        1.1   thorpej #ifdef CONSDEBUG
    239        1.1   thorpej 	whichconsole = ++whichconsole % (NITE+1);
    240        1.1   thorpej #endif
    241        1.1   thorpej 
    242        1.1   thorpej 	if (itecons != -1)
    243        1.1   thorpej 		return;
    244        1.1   thorpej 
    245        1.1   thorpej 	iteconfig();
    246        1.1   thorpej 	unit = -1;
    247        1.1   thorpej 	pri = CN_DEAD;
    248        1.1   thorpej 	for (ite = 0; ite < NITE; ite++) {
    249        1.1   thorpej #ifdef CONSDEBUG
    250        1.1   thorpej 		if (ite < whichconsole)
    251        1.1   thorpej 			continue;
    252        1.1   thorpej #endif
    253        1.1   thorpej 		ip = &ite_data[ite];
    254       1.14   tsutsui 		if (ip->alive == 0)
    255        1.1   thorpej 			continue;
    256        1.7   tsutsui 		if ((int)ip->regbase == INTIOBASE + FB_BASE) {
    257        1.1   thorpej 			pri = CN_INTERNAL;
    258        1.1   thorpej 			unit = ite;
    259        1.1   thorpej 		} else if (unit < 0) {
    260        1.1   thorpej 			pri = CN_NORMAL;
    261        1.1   thorpej 			unit = ite;
    262        1.1   thorpej 		}
    263        1.1   thorpej 	}
    264        1.1   thorpej 	curcons_scode = ite_scode[unit];
    265        1.1   thorpej 	cp->cn_dev = unit;
    266        1.1   thorpej 	cp->cn_pri = pri;
    267        1.1   thorpej }
    268        1.1   thorpej 
    269        1.1   thorpej void
    270        1.4   tsutsui iteinit(struct consdev *cp)
    271        1.1   thorpej {
    272        1.1   thorpej 	int ite = cp->cn_dev;
    273        1.1   thorpej 	struct ite_data *ip;
    274        1.1   thorpej 
    275        1.1   thorpej 	if (itecons != -1)
    276        1.1   thorpej 		return;
    277        1.1   thorpej 
    278        1.1   thorpej 	ip = &ite_data[ite];
    279        1.1   thorpej 
    280        1.1   thorpej 	ip->curx = 0;
    281        1.1   thorpej 	ip->cury = 0;
    282        1.1   thorpej 	ip->cursorx = 0;
    283        1.1   thorpej 	ip->cursory = 0;
    284        1.1   thorpej 
    285        1.1   thorpej 	(*ip->isw->ite_init)(ip);
    286        1.1   thorpej 	(*ip->isw->ite_cursor)(ip, DRAW_CURSOR);
    287        1.1   thorpej 
    288        1.1   thorpej 	itecons = ite;
    289        1.1   thorpej 	kbdinit();
    290        1.1   thorpej }
    291        1.1   thorpej 
    292        1.1   thorpej /* ARGSUSED */
    293        1.1   thorpej void
    294        1.4   tsutsui iteputchar(dev_t dev, int c)
    295        1.1   thorpej {
    296        1.3   tsutsui 	struct ite_data *ip = &ite_data[itecons];
    297        1.3   tsutsui 	struct itesw *sp = ip->isw;
    298        1.1   thorpej 
    299        1.1   thorpej 	c &= 0x7F;
    300        1.1   thorpej 	switch (c) {
    301        1.1   thorpej 
    302        1.1   thorpej 	case '\n':
    303        1.1   thorpej 		if (++ip->cury == ip->rows) {
    304        1.1   thorpej 			ip->cury--;
    305       1.14   tsutsui 			(*sp->ite_scroll)(ip);
    306        1.1   thorpej 			ite_clrtoeol(ip, sp, ip->cury, 0);
    307        1.1   thorpej 		}
    308        1.1   thorpej 		else
    309        1.1   thorpej 			(*sp->ite_cursor)(ip, MOVE_CURSOR);
    310        1.1   thorpej 		break;
    311        1.1   thorpej 
    312        1.1   thorpej 	case '\r':
    313        1.1   thorpej 		ip->curx = 0;
    314        1.1   thorpej 		(*sp->ite_cursor)(ip, MOVE_CURSOR);
    315        1.1   thorpej 		break;
    316        1.1   thorpej 
    317        1.1   thorpej 	case '\b':
    318        1.1   thorpej 		if (--ip->curx < 0)
    319        1.1   thorpej 			ip->curx = 0;
    320        1.1   thorpej 		else
    321        1.1   thorpej 			(*sp->ite_cursor)(ip, MOVE_CURSOR);
    322        1.1   thorpej 		break;
    323        1.1   thorpej 
    324        1.1   thorpej 	default:
    325        1.1   thorpej 		if (c < ' ' || c == 0177)
    326        1.1   thorpej 			break;
    327       1.14   tsutsui 		(*sp->ite_putc)(ip, c, ip->cury, ip->curx);
    328        1.1   thorpej 		(*sp->ite_cursor)(ip, DRAW_CURSOR);
    329        1.1   thorpej 		itecheckwrap(ip, sp);
    330        1.1   thorpej 		break;
    331        1.1   thorpej 	}
    332        1.1   thorpej }
    333        1.1   thorpej 
    334        1.3   tsutsui static void
    335        1.4   tsutsui itecheckwrap(struct ite_data *ip, struct itesw *sp)
    336        1.1   thorpej {
    337        1.1   thorpej 	if (++ip->curx == ip->cols) {
    338        1.1   thorpej 		ip->curx = 0;
    339        1.1   thorpej 		if (++ip->cury == ip->rows) {
    340        1.1   thorpej 			--ip->cury;
    341       1.14   tsutsui 			(*sp->ite_scroll)(ip);
    342        1.1   thorpej 			ite_clrtoeol(ip, sp, ip->cury, 0);
    343        1.1   thorpej 			return;
    344        1.1   thorpej 		}
    345        1.1   thorpej 	}
    346        1.1   thorpej 	(*sp->ite_cursor)(ip, MOVE_CURSOR);
    347        1.1   thorpej }
    348        1.1   thorpej 
    349        1.3   tsutsui static void
    350        1.4   tsutsui ite_clrtoeol(struct ite_data *ip, struct itesw *sp, int y, int x)
    351        1.1   thorpej {
    352        1.4   tsutsui 
    353        1.1   thorpej 	(*sp->ite_clear)(ip, y, x, 1, ip->cols - x);
    354        1.1   thorpej 	(*sp->ite_cursor)(ip, DRAW_CURSOR);
    355        1.1   thorpej }
    356        1.1   thorpej 
    357        1.1   thorpej /* ARGSUSED */
    358        1.1   thorpej int
    359        1.4   tsutsui itegetchar(dev_t dev)
    360        1.1   thorpej {
    361        1.3   tsutsui 
    362        1.1   thorpej #ifdef SMALL
    363        1.3   tsutsui 	return 0;
    364        1.1   thorpej #else
    365        1.3   tsutsui 	return kbdgetc();
    366        1.1   thorpej #endif
    367        1.1   thorpej }
    368        1.1   thorpej #endif
    369