Expand PMF_FN_* macros.
[netbsd-mini2440.git] / sys / arch / ews4800mips / stand / common / console.c
blob7580aa9d7bfc38b5eaa96079ba53075964ddcd67
1 /* $NetBSD: console.c,v 1.3 2007/02/22 05:31:53 thorpej Exp $ */
3 /*-
4 * Copyright (c) 2004, 2005 The NetBSD Foundation, Inc.
5 * All rights reserved.
7 * This code is derived from software contributed to The NetBSD Foundation
8 * by UCHIYAMA Yasushi.
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.
19 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
20 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
21 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
22 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
23 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29 * POSSIBILITY OF SUCH DAMAGE.
32 #include <sys/param.h>
33 #include <sys/systm.h>
35 #include <lib/libsa/stand.h>
37 #include "local.h"
39 void __putchar(int);
41 #define PUTCHAR __putchar /* "boot" hooks log staff. */
43 #include <machine/sbd.h>
45 #include "console.h"
47 struct cons cons;
48 void nullcursor(int, int);
49 void nullscroll(void);
52 void
53 console_init(void)
55 uint8_t nvsram_cons;
57 cons.cursor = nullcursor;
58 cons.scroll = nullscroll;
59 cons.cursor_enable = false;
60 cons.erace_previous_cursor = false;
62 switch (SBD_INFO->machine) {
63 case MACHINE_TR2:
64 /* untested */
65 nvsram_cons = *(volatile uint8_t *)0xbb023010;
67 switch (nvsram_cons) {
68 case 0x00:
69 cons.type = CONS_FB_KSEG2;
70 fb_set_addr(0xf0000000, 0x01000000, 0xbfc0ec00);
71 zskbd_set_addr(0xbb010000, 0xbb010004);
72 cons.init();
73 break;
74 case 0x01:
75 /* sio 1 (zs channel A) */
76 cons.type = CONS_SIO1;
77 zs_set_addr(0xbb011008, 0xbb01100c, 4915200);
78 cons.init();
79 break;
80 case 0x02:
81 /* sio 2 (zs channel B) */
82 cons.type = CONS_SIO2;
83 zs_set_addr(0xbb011000, 0xbb011004, 4915200);
84 cons.init();
85 break;
86 default:
87 goto rom_cons;
89 break;
90 case MACHINE_TR2A:
91 nvsram_cons = *(volatile uint8_t *)0xbe4932a0;
93 switch (nvsram_cons) {
94 case 0x80:
95 /* on-board FB on 360AD, 360ADII */
96 cons.type = CONS_FB_KSEG2;
97 fb_set_addr(0xf0000000, 0x01000000, 0xbfc0ec00);
98 zskbd_set_addr(0xbe480000, 0xbe480004);
99 cons.init();
100 break;
101 case 0x01:
102 /* sio 1 (zs channel A) */
103 cons.type = CONS_SIO1;
104 zs_set_addr(0xbe440008, 0xbe44000c, 4915200);
105 cons.init();
106 break;
107 case 0x02:
108 /* sio 2 (zs channel B) */
109 cons.type = CONS_SIO2;
110 zs_set_addr(0xbe440000, 0xbe440004, 4915200);
111 cons.init();
112 break;
113 default:
114 goto rom_cons;
116 break;
117 default:
118 rom_cons:
119 cons.getc = ROM_GETC;
120 cons.scan = rom_scan;
121 cons.putc = ROM_PUTC;
122 cons.init = cons_rom_init;
123 cons.scroll = cons_rom_scroll;
124 cons.type = CONS_ROM;
125 cons.init();
127 break;
131 void
132 console_cursor(bool on)
135 cons.cursor_enable = on;
138 enum console_type
139 console_type(void)
142 return cons.type;
145 void
146 PUTCHAR(int c)
148 int i;
150 if (cons.type == CONS_SIO1 || cons.type == CONS_SIO2) {
151 if (c == '\n')
152 cons.putc(0, 0, '\r');
153 cons.putc(0, 0, c);
154 return;
157 if (cons.cursor_enable && cons.erace_previous_cursor)
158 cons.cursor(cons.x * ROM_FONT_WIDTH, cons.y * ROM_FONT_HEIGHT);
160 switch (c) {
161 default:
162 cons.putc(cons.x * ROM_FONT_WIDTH, cons.y * ROM_FONT_HEIGHT, c);
163 if (++cons.x == CONS_WIDTH) {
164 cons.x = X_INIT;
165 cons.y++;
167 break;
168 case '\b':
169 cons.putc(cons.x * ROM_FONT_WIDTH, cons.y * ROM_FONT_HEIGHT, c);
170 cons.x = cons.x == X_INIT ? X_INIT : cons.x - 1;
171 if (cons.cursor_enable)
172 cons.putc(cons.x * ROM_FONT_WIDTH,
173 cons.y * ROM_FONT_HEIGHT, ' ');
174 cons.putc(cons.x * ROM_FONT_WIDTH, cons.y * ROM_FONT_HEIGHT, c);
175 break;
176 case '\t':
177 for (i = cons.x % 8; i < 8; i++) {
178 cons.putc(cons.x * ROM_FONT_WIDTH,
179 cons.y * ROM_FONT_HEIGHT, ' ');
180 if (++cons.x == CONS_WIDTH) {
181 cons.x = X_INIT;
182 if (++cons.y == CONS_HEIGHT)
183 cons.scroll();
186 break;
187 case '\r':
188 cons.putc(cons.x * ROM_FONT_WIDTH, cons.y * ROM_FONT_HEIGHT, c);
189 cons.x = X_INIT;
190 break;
191 case '\n':
192 cons.putc(cons.x * ROM_FONT_WIDTH, cons.y * ROM_FONT_HEIGHT,
193 '\r');
194 cons.putc(cons.x * ROM_FONT_WIDTH, cons.y * ROM_FONT_HEIGHT, c);
195 cons.x = X_INIT;
196 cons.y++;
197 break;
198 case 2: /* Ctrl-b */
199 if (--cons.x < X_INIT)
200 cons.x = X_INIT;
201 break;
202 case 6: /* Ctrl-f */
203 if (++cons.x >= CONS_WIDTH)
204 cons.x = CONS_WIDTH;
205 break;
206 case 11:/* Ctrl-k */
207 for (i = cons.x; i < CONS_WIDTH; i++)
208 cons.putc(i * ROM_FONT_WIDTH, cons.y * ROM_FONT_HEIGHT,
209 ' ');
210 break;
213 if (cons.y == CONS_HEIGHT)
214 cons.scroll();
216 if (cons.cursor_enable) {
217 cons.cursor(cons.x * ROM_FONT_WIDTH, cons.y * ROM_FONT_HEIGHT);
218 cons.erace_previous_cursor = true;
219 } else {
220 cons.erace_previous_cursor = false;
225 getchar(void)
228 return cons.getc();
232 cnscan(void)
235 return cons.scan();
238 void
239 nullcursor(int x, int y)
241 /* place holder */
244 void
245 nullscroll(void)
247 /* place holder */