1 /* 2 * 3 * Copyright (c) 1995 Charles D. Cranor and Seth Widoff 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 by Charles D. Cranor 17 * and Seth Widoff. 18 * 4. The name of the author may not be used to endorse or promote products 19 * derived from this software without specific prior written permission. 20 * 21 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 22 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 23 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 24 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 25 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 26 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 27 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 28 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 29 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 30 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 31 */ 32 /* 33 * console i/o 34 */ 35 36 #include "sboot.h" 37 38 /* 39 * hardware 40 */ 41 42 struct zs_hw { 43 volatile u_char ctl; 44 volatile u_char data; 45 }; 46 47 struct zs_hw *zs = (struct zs_hw *)CONS_ZS_ADDR; 48 49 /* 50 * consinit: init console 51 */ 52 53 consinit() 54 55 { 56 register int mark = time(); 57 register int rr1; 58 while (1) { 59 if (time() > mark + 5) break; 60 zs->ctl = 1; rr1 = zs->ctl; 61 zs->ctl = 0; 62 if ((rr1 & 0x1) == 1 && (zs->ctl & 0x4) == 4) break; /* zs_drain! */ 63 } 64 zs->ctl = 9; zs->ctl = 0x00; /* clear interrupt */ 65 zs->ctl = 4; zs->ctl = 0x44; /* 16x clk, 1 stop bit */ 66 zs->ctl = 5; zs->ctl = 0xea; /* DTR on, 8 bit xmit, xmit on, RTS on */ 67 zs->ctl = 3; zs->ctl = 0xc1; /* 8 bit recv, auto cd_cts, recv on */ 68 zs->ctl = 1; zs->ctl = 0x00; /* no intrs */ 69 zs->ctl = 2; zs->ctl = 0x00; /* no vector */ 70 zs->ctl = 10; zs->ctl = 0x00; /* */ 71 zs->ctl = 11; zs->ctl = 0x50; /* clocking options */ 72 zs->ctl = 12; zs->ctl = 0x0e; /* 9600 baud, part 1 */ 73 zs->ctl = 13; zs->ctl = 0x00; /* 9600 baud, part 2 */ 74 zs->ctl = 14; zs->ctl = 0x03; /* more clocking options */ 75 zs->ctl = 15; zs->ctl = 0x00; /* clear intrs */ 76 } 77 78 /* 79 * putchar: put char to console 80 */ 81 82 void putchar(char c) 83 { 84 if (c == '\n') putchar('\r'); /* avoid the need for \r\n in printf */ 85 zs->ctl = 0; 86 while ((zs->ctl & 0x04) == 0) { 87 zs->ctl = 0; 88 } 89 zs->ctl = 8; 90 zs->ctl = c; 91 } 92 93 /* 94 * cngetc: get 1 char from console 95 */ 96 97 char cngetc () 98 { 99 zs->ctl = 0; 100 while ((zs->ctl & 0x1) == 0) { 101 zs->ctl = 0; 102 } 103 zs->ctl = 8; 104 return zs->ctl; 105 } 106 107 /* 108 * puts: put string to console 109 */ 110 111 void puts ( char * str ) 112 { 113 while ( *str != '\0' ) { 114 putchar(*str); 115 str++; 116 } 117 } 118 119 /* 120 * ngets: get string from console 121 */ 122 123 char *ngets ( char * str, int size ) 124 { 125 int i = 0; 126 while ( (i < size - 1) && (str[i] = cngetc()) != '\r') { 127 if ( str[i] == '\b' || str[i] == 0x7F ) { 128 if ( i == 0) continue; 129 i--; 130 puts("\b \b"); 131 continue; 132 } 133 putchar(str[i]); 134 i++; 135 } 136 puts("\n"); 137 str[i] = '\0'; 138 return(&str[i]); 139 } 140 141