Home | History | Annotate | Line # | Download | only in common
console.c revision 1.1
      1 /*	$NetBSD: console.c,v 1.1 2005/12/29 15:20:09 tsutsui Exp $	*/
      2 
      3 /*-
      4  * Copyright (c) 2004, 2005 The NetBSD Foundation, Inc.
      5  * All rights reserved.
      6  *
      7  * This code is derived from software contributed to The NetBSD Foundation
      8  * by UCHIYAMA Yasushi.
      9  *
     10  * Redistribution and use in source and binary forms, with or without
     11  * modification, are permitted provided that the following conditions
     12  * are met:
     13  * 1. Redistributions of source code must retain the above copyright
     14  *    notice, this list of conditions and the following disclaimer.
     15  * 2. Redistributions in binary form must reproduce the above copyright
     16  *    notice, this list of conditions and the following disclaimer in the
     17  *    documentation and/or other materials provided with the distribution.
     18  * 3. All advertising materials mentioning features or use of this software
     19  *    must display the following acknowledgement:
     20  *        This product includes software developed by the NetBSD
     21  *        Foundation, Inc. and its contributors.
     22  * 4. Neither the name of The NetBSD Foundation nor the names of its
     23  *    contributors may be used to endorse or promote products derived
     24  *    from this software without specific prior written permission.
     25  *
     26  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
     27  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
     28  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     29  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
     30  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     31  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     32  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     33  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
     34  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     35  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     36  * POSSIBILITY OF SUCH DAMAGE.
     37  */
     38 
     39 #include <sys/param.h>
     40 #include <sys/systm.h>
     41 
     42 #include <lib/libsa/stand.h>
     43 
     44 #include "local.h"
     45 
     46 void __putchar(int);
     47 
     48 #define	PUTCHAR		__putchar	/* "boot" hooks log staff. */
     49 
     50 #include <machine/sbd.h>
     51 
     52 #include "console.h"
     53 
     54 struct cons cons;
     55 void nullcursor(int, int);
     56 void nullscroll(void);
     57 
     58 
     59 void
     60 console_init(void)
     61 {
     62 	uint8_t nvsram_cons;
     63 
     64 	cons.cursor = nullcursor;
     65 	cons.scroll = nullscroll;
     66 	cons.cursor_enable = FALSE;
     67 	cons.erace_previous_cursor = FALSE;
     68 
     69 	switch (SBD_INFO->machine) {
     70 	case MACHINE_TR2:
     71 		/* untested */
     72 		nvsram_cons = *(volatile uint8_t *)0xbb023010;
     73 
     74 		switch (nvsram_cons) {
     75 		case 0x00:
     76 			cons.type = CONS_FB_KSEG2;
     77 			fb_set_addr(0xf0000000, 0x01000000, 0xbfc0ec00);
     78 			zskbd_set_addr(0xbb010000, 0xbb010004);
     79 			cons.init();
     80 			break;
     81 		case 0x01:
     82 			/* sio 1 (zs channel A) */
     83 			cons.type = CONS_SIO1;
     84 			zs_set_addr(0xbb011008, 0xbb01100c, 4915200);
     85 			cons.init();
     86 			break;
     87 		case 0x02:
     88 			/* sio 2 (zs channel B) */
     89 			cons.type = CONS_SIO2;
     90 			zs_set_addr(0xbb011000, 0xbb011004, 4915200);
     91 			cons.init();
     92 			break;
     93 		default:
     94 			goto rom_cons;
     95 		}
     96 		break;
     97 	case MACHINE_TR2A:
     98 		nvsram_cons = *(volatile uint8_t *)0xbe4932a0;
     99 
    100 		switch (nvsram_cons) {
    101 		case 0x80:
    102 			/* on-board FB on 360AD, 360ADII */
    103 			cons.type = CONS_FB_KSEG2;
    104 			fb_set_addr(0xf0000000, 0x01000000, 0xbfc0ec00);
    105 			zskbd_set_addr(0xbe480000, 0xbe480004);
    106 			cons.init();
    107 			break;
    108 		case 0x01:
    109 			/* sio 1 (zs channel A) */
    110 			cons.type = CONS_SIO1;
    111 			zs_set_addr(0xbe440008, 0xbe44000c, 4915200);
    112 			cons.init();
    113 			break;
    114 		case 0x02:
    115 			/* sio 2 (zs channel B) */
    116 			cons.type = CONS_SIO2;
    117 			zs_set_addr(0xbe440000, 0xbe440004, 4915200);
    118 			cons.init();
    119 			break;
    120 		default:
    121 			goto rom_cons;
    122 		}
    123 		break;
    124 	default:
    125  rom_cons:
    126 		cons.getc = ROM_GETC;
    127 		cons.scan = rom_scan;
    128 		cons.putc = ROM_PUTC;
    129 		cons.init = cons_rom_init;
    130 		cons.scroll = cons_rom_scroll;
    131 		cons.type = CONS_ROM;
    132 		cons.init();
    133 
    134 		break;
    135 	}
    136 }
    137 
    138 void
    139 console_cursor(boolean_t on)
    140 {
    141 
    142 	cons.cursor_enable = on;
    143 }
    144 
    145 enum console_type
    146 console_type(void)
    147 {
    148 
    149 	return cons.type;
    150 }
    151 
    152 void
    153 PUTCHAR(int c)
    154 {
    155 	int i;
    156 
    157 	if (cons.type == CONS_SIO1 || cons.type == CONS_SIO2) {
    158 		if (c == '\n')
    159 			cons.putc(0, 0, '\r');
    160 		cons.putc(0, 0, c);
    161 		return;
    162 	}
    163 
    164 	if (cons.cursor_enable && cons.erace_previous_cursor)
    165 		cons.cursor(cons.x * ROM_FONT_WIDTH, cons.y * ROM_FONT_HEIGHT);
    166 
    167 	switch (c) {
    168 	default:
    169 		cons.putc(cons.x * ROM_FONT_WIDTH, cons.y * ROM_FONT_HEIGHT, c);
    170 		if (++cons.x == CONS_WIDTH) {
    171 			cons.x = X_INIT;
    172 			cons.y++;
    173 		}
    174 		break;
    175 	case '\b':
    176 		cons.putc(cons.x * ROM_FONT_WIDTH, cons.y * ROM_FONT_HEIGHT, c);
    177 		cons.x = cons.x == X_INIT ? X_INIT : cons.x - 1;
    178 		if (cons.cursor_enable)
    179 			cons.putc(cons.x * ROM_FONT_WIDTH,
    180 			    cons.y * ROM_FONT_HEIGHT, ' ');
    181 		cons.putc(cons.x * ROM_FONT_WIDTH, cons.y * ROM_FONT_HEIGHT, c);
    182 		break;
    183 	case '\t':
    184 		for (i = cons.x % 8; i < 8; i++) {
    185 			cons.putc(cons.x * ROM_FONT_WIDTH,
    186 			    cons.y * ROM_FONT_HEIGHT, ' ');
    187 			if (++cons.x == CONS_WIDTH) {
    188 				cons.x = X_INIT;
    189 				if (++cons.y == CONS_HEIGHT)
    190 					cons.scroll();
    191 			}
    192 		}
    193 		break;
    194 	case '\r':
    195 		cons.putc(cons.x * ROM_FONT_WIDTH, cons.y * ROM_FONT_HEIGHT, c);
    196 		cons.x = X_INIT;
    197 		break;
    198 	case '\n':
    199 		cons.putc(cons.x * ROM_FONT_WIDTH, cons.y * ROM_FONT_HEIGHT,
    200 		    '\r');
    201 		cons.putc(cons.x * ROM_FONT_WIDTH, cons.y * ROM_FONT_HEIGHT, c);
    202 		cons.x = X_INIT;
    203 		cons.y++;
    204 		break;
    205 	case 2:	/* Ctrl-b */
    206 		if (--cons.x < X_INIT)
    207 			cons.x = X_INIT;
    208 		break;
    209 	case 6:	/* Ctrl-f */
    210 		if (++cons.x >= CONS_WIDTH)
    211 			cons.x = CONS_WIDTH;
    212 		break;
    213 	case 11:/* Ctrl-k */
    214 		for (i = cons.x; i < CONS_WIDTH; i++)
    215 			cons.putc(i * ROM_FONT_WIDTH, cons.y * ROM_FONT_HEIGHT,
    216 			     ' ');
    217 		break;
    218 	}
    219 
    220 	if (cons.y == CONS_HEIGHT)
    221 		cons.scroll();
    222 
    223 	if (cons.cursor_enable) {
    224 		cons.cursor(cons.x * ROM_FONT_WIDTH, cons.y * ROM_FONT_HEIGHT);
    225 		cons.erace_previous_cursor = TRUE;
    226 	} else {
    227 		cons.erace_previous_cursor = FALSE;
    228 	}
    229 }
    230 
    231 int
    232 getchar(void)
    233 {
    234 
    235 	return cons.getc();
    236 }
    237 
    238 int
    239 cnscan(void)
    240 {
    241 
    242 	return cons.scan();
    243 }
    244 
    245 void
    246 nullcursor(int x, int y)
    247 {
    248 	/* place holder */
    249 }
    250 
    251 void
    252 nullscroll(void)
    253 {
    254 	/* place holder */
    255 }
    256