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