1 /* $NetBSD: consio.c,v 1.13 2002/05/24 21:40:59 ragge Exp $ */ 2 /* 3 * Copyright (c) 1994, 1998 Ludd, University of Lule}, Sweden. 4 * All rights reserved. 5 * 6 * Redistribution and use in source and binary forms, with or without 7 * modification, are permitted provided that the following conditions 8 * are met: 9 * 1. Redistributions of source code must retain the above copyright 10 * notice, this list of conditions and the following disclaimer. 11 * 2. Redistributions in binary form must reproduce the above copyright 12 * notice, this list of conditions and the following disclaimer in the 13 * documentation and/or other materials provided with the distribution. 14 * 3. All advertising materials mentioning features or use of this software 15 * must display the following acknowledgement: 16 * This product includes software developed at Ludd, University of Lule}. 17 * 4. The name of the author may not be used to endorse or promote products 18 * derived from this software without specific prior written permission 19 * 20 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 21 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 22 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 23 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 24 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 25 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 26 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 27 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 28 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 29 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 30 */ 31 32 /* All bugs are subject to removal without further notice */ 33 34 35 36 #include "sys/param.h" 37 38 #include "../vax/gencons.h" 39 40 #include "mtpr.h" 41 #include "sid.h" 42 #include "rpb.h" 43 #include "ka630.h" 44 45 #include "data.h" 46 47 void setup __P((void)); 48 49 static void (*put_fp) __P((int)) = NULL; 50 static int (*get_fp) __P((void)) = NULL; 51 static int (*test_fp) __P((void)) = NULL; 52 53 void pr_putchar __P((int c)); /* putchar() using mtpr/mfpr */ 54 int pr_getchar __P((void)); 55 int pr_testchar __P((void)); 56 57 void rom_putchar __P((int c)); /* putchar() using ROM routines */ 58 int rom_getchar __P((void)); 59 int rom_testchar __P((void)); 60 61 int rom_putc; /* ROM-address of put-routine */ 62 int rom_getc; /* ROM-address of get-routine */ 63 64 /* Pointer to KA630 console page, initialized by ka630_consinit */ 65 unsigned char *ka630_conspage; 66 67 /* Function that initializes things for KA630 ROM console I/O */ 68 void ka630_consinit __P((void)); 69 70 /* Functions that use KA630 ROM for console I/O */ 71 void ka630_rom_putchar __P((int c)); 72 int ka630_rom_getchar __P((void)); 73 int ka630_rom_testchar __P((void)); 74 75 /* Also added such a thing for KA53 - MK-991208 */ 76 unsigned char *ka53_conspage; 77 void ka53_consinit(void); 78 79 void ka53_rom_putchar(int c); 80 int ka53_rom_getchar(void); 81 int ka53_rom_testchar(void); 82 83 void vxt_putchar(int c); 84 int vxt_getchar(void); 85 int vxt_testchar(void); 86 87 void putchar(int); 88 int getchar(void); 89 int testkey(void); 90 void consinit(void); 91 void _rtt(void); 92 93 void 94 putchar(int c) 95 { 96 (*put_fp)(c); 97 if (c == 10) 98 (*put_fp)(13); /* CR/LF */ 99 } 100 101 int 102 getchar(void) 103 { 104 int c; 105 106 do 107 c = (*get_fp)() & 0177; 108 while (c == 17 || c == 19); /* ignore XON/XOFF */ 109 if (c < 96 && c > 64) 110 c += 32; 111 return c; 112 } 113 114 int 115 testkey(void) 116 { 117 return (*test_fp)(); 118 } 119 120 /* 121 * setup() is called out of the startup files (start.s, srt0.s) and 122 * initializes data which are globally used and is called before main(). 123 */ 124 void 125 consinit(void) 126 { 127 put_fp = pr_putchar; /* Default */ 128 get_fp = pr_getchar; 129 test_fp = pr_testchar; 130 131 /* 132 * According to the vax_boardtype (vax_cputype is not specific 133 * enough to do that) we decide which method/routines to use 134 * for console I/O. 135 * mtpr/mfpr are restricted to serial consoles, ROM-based routines 136 * support both serial and graphical consoles. 137 * We default to mtpr routines; so that we don't crash if 138 * it isn't a supported system. 139 */ 140 switch (vax_boardtype) { 141 142 case VAX_BTYP_43: 143 case VAX_BTYP_410: 144 case VAX_BTYP_420: 145 put_fp = rom_putchar; 146 get_fp = rom_getchar; 147 test_fp = rom_testchar; 148 rom_putc = 0x20040058; /* 537133144 */ 149 rom_getc = 0x20040044; /* 537133124 */ 150 break; 151 152 case VAX_BTYP_VXT: 153 put_fp = vxt_putchar; 154 get_fp = vxt_getchar; 155 test_fp = vxt_testchar; 156 break; 157 158 case VAX_BTYP_630: 159 ka630_consinit(); 160 break; 161 162 case VAX_BTYP_46: 163 case VAX_BTYP_48: 164 case VAX_BTYP_49: 165 put_fp = rom_putchar; 166 get_fp = rom_getchar; 167 test_fp = rom_testchar; 168 rom_putc = 0x20040068; 169 rom_getc = 0x20040054; 170 break; 171 172 case VAX_BTYP_53: 173 ka53_consinit(); 174 break; 175 176 #ifdef notdef 177 case VAX_BTYP_630: 178 case VAX_BTYP_650: 179 case VAX_BTYP_9CC: 180 case VAX_BTYP_60: 181 put_fp = pr_putchar; 182 get_fp = pr_getchar; 183 break 184 #endif 185 } 186 return; 187 } 188 189 /* 190 * putchar() using MTPR 191 */ 192 void 193 pr_putchar(int c) 194 { 195 int timeout = 1<<15; /* don't hang the machine! */ 196 197 /* 198 * On KA88 we may get C-S/C-Q from the console. 199 * Must obey it. 200 */ 201 while (mfpr(PR_RXCS) & GC_DON) { 202 if ((mfpr(PR_RXDB) & 0x7f) == 19) { 203 while (1) { 204 while ((mfpr(PR_RXCS) & GC_DON) == 0) 205 ; 206 if ((mfpr(PR_RXDB) & 0x7f) == 17) 207 break; 208 } 209 } 210 } 211 212 while ((mfpr(PR_TXCS) & GC_RDY) == 0) /* Wait until xmit ready */ 213 if (--timeout < 0) 214 break; 215 mtpr(c, PR_TXDB); /* xmit character */ 216 } 217 218 /* 219 * getchar() using MFPR 220 */ 221 int 222 pr_getchar(void) 223 { 224 while ((mfpr(PR_RXCS) & GC_DON) == 0) 225 ; /* wait for char */ 226 return (mfpr(PR_RXDB)); /* now get it */ 227 } 228 229 int 230 pr_testchar(void) 231 { 232 if (mfpr(PR_RXCS) & GC_DON) 233 return mfpr(PR_RXDB); 234 else 235 return 0; 236 } 237 238 /* 239 * void ka630_rom_getchar (void) ==> initialize KA630 ROM console I/O 240 */ 241 void ka630_consinit(void) 242 { 243 short *NVR; 244 int i; 245 246 /* Find the console page */ 247 NVR = (short *) KA630_NVR_ADRS; 248 249 i = *NVR++ & 0xFF; 250 i |= (*NVR++ & 0xFF) << 8; 251 i |= (*NVR++ & 0xFF) << 16; 252 i |= (*NVR++ & 0xFF) << 24; 253 254 ka630_conspage = (char *) i; 255 256 /* Go to last row to minimize confusion */ 257 ka630_conspage[KA630_ROW] = ka630_conspage[KA630_MAXROW]; 258 ka630_conspage[KA630_COL] = ka630_conspage[KA630_MINCOL]; 259 260 /* Use KA630 ROM console I/O routines */ 261 put_fp = ka630_rom_putchar; 262 get_fp = ka630_rom_getchar; 263 test_fp = ka630_rom_testchar; 264 } 265 266 267 /* 268 * void ka53_consinit (void) ==> initialize KA53 ROM console I/O 269 */ 270 void ka53_consinit(void) 271 { 272 ka53_conspage = (char *) 0x2014044b; 273 274 put_fp = ka53_rom_putchar; 275 get_fp = ka53_rom_getchar; 276 test_fp = ka53_rom_testchar; 277 } 278 279 static volatile int *vxtregs = (int *)0x200A0000; 280 281 #define CH_SR 1 282 #define CH_DAT 3 283 #define SR_TX_RDY 0x04 284 #define SR_RX_RDY 0x01 285 286 void 287 vxt_putchar(int c) 288 { 289 while ((vxtregs[CH_SR] & SR_TX_RDY) == 0) 290 ; 291 vxtregs[CH_DAT] = c; 292 } 293 294 int 295 vxt_getchar(void) 296 { 297 while ((vxtregs[CH_SR] & SR_RX_RDY) == 0) 298 ; 299 return vxtregs[CH_DAT]; 300 } 301 302 int 303 vxt_testchar(void) 304 { 305 if ((vxtregs[CH_SR] & SR_RX_RDY) == 0) 306 return 0; 307 return vxtregs[CH_DAT]; 308 } 309