pcio.c revision 1.4 1 1.4 drochner /* $NetBSD: pcio.c,v 1.4 1997/06/13 13:41:20 drochner Exp $ */
2 1.1 perry
3 1.1 perry /*
4 1.1 perry * Copyright (c) 1996
5 1.1 perry * Matthias Drochner. All rights reserved.
6 1.1 perry *
7 1.1 perry * Redistribution and use in source and binary forms, with or without
8 1.1 perry * modification, are permitted provided that the following conditions
9 1.1 perry * are met:
10 1.1 perry * 1. Redistributions of source code must retain the above copyright
11 1.1 perry * notice, this list of conditions and the following disclaimer.
12 1.1 perry * 2. Redistributions in binary form must reproduce the above copyright
13 1.1 perry * notice, this list of conditions and the following disclaimer in the
14 1.1 perry * documentation and/or other materials provided with the distribution.
15 1.1 perry * 3. All advertising materials mentioning features or use of this software
16 1.1 perry * must display the following acknowledgement:
17 1.1 perry * This product includes software developed for the NetBSD Project
18 1.1 perry * by Matthias Drochner.
19 1.1 perry * 4. The name of the author may not be used to endorse or promote products
20 1.1 perry * derived from this software without specific prior written permission.
21 1.1 perry *
22 1.1 perry * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
23 1.1 perry * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
24 1.1 perry * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
25 1.1 perry * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
26 1.1 perry * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
27 1.1 perry * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
28 1.1 perry * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
29 1.1 perry * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
30 1.1 perry * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
31 1.1 perry * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32 1.1 perry *
33 1.1 perry */
34 1.1 perry
35 1.3 thorpej /*
36 1.4 drochner * console I/O
37 1.4 drochner * needs lowlevel routines from conio.S and comio.S
38 1.3 thorpej */
39 1.1 perry
40 1.1 perry #include <lib/libsa/stand.h>
41 1.1 perry
42 1.1 perry #include "libi386.h"
43 1.1 perry
44 1.1 perry extern void conputc __P((int));
45 1.1 perry extern int congetc __P((void));
46 1.1 perry extern int coniskey __P((void));
47 1.1 perry
48 1.1 perry #ifdef SUPPORT_SERIAL
49 1.4 drochner extern void cominit __P((int));
50 1.2 perry extern int computc __P((int, int));
51 1.2 perry extern int comgetc __P((int));
52 1.2 perry extern int comstatus __P((int));
53 1.1 perry
54 1.3 thorpej static int iodev;
55 1.1 perry #endif
56 1.1 perry
57 1.3 thorpej static char *iodevname[] = {
58 1.3 thorpej "pc",
59 1.1 perry #ifdef SUPPORT_SERIAL
60 1.3 thorpej "com0",
61 1.3 thorpej "com1"
62 1.1 perry #endif
63 1.1 perry };
64 1.1 perry
65 1.3 thorpej char *
66 1.3 thorpej initio(dev)
67 1.3 thorpej int dev;
68 1.1 perry {
69 1.1 perry #ifdef SUPPORT_SERIAL
70 1.3 thorpej switch (dev) {
71 1.3 thorpej case CONSDEV_AUTO:
72 1.3 thorpej /*
73 1.3 thorpej * serial console must have hardware handshake! check: 1.
74 1.3 thorpej * character output without error 2. status bits for modem
75 1.3 thorpej * ready set (status seems only useful after character
76 1.3 thorpej * output)
77 1.3 thorpej */
78 1.3 thorpej cominit(0);
79 1.3 thorpej if (!(computc(' ', 0) & 0x80) && (comstatus(0) & 0x00b0))
80 1.3 thorpej dev = CONSDEV_COM0;
81 1.3 thorpej else {
82 1.3 thorpej cominit(1);
83 1.3 thorpej if (!(computc(' ', 1) & 0x80) && (comstatus(1) & 0x00b0))
84 1.3 thorpej dev = CONSDEV_COM1;
85 1.3 thorpej else
86 1.3 thorpej dev = CONSDEV_PC;
87 1.3 thorpej }
88 1.3 thorpej break;
89 1.3 thorpej case CONSDEV_COM0:
90 1.3 thorpej cominit(0);
91 1.3 thorpej break;
92 1.3 thorpej case CONSDEV_COM1:
93 1.3 thorpej cominit(1);
94 1.3 thorpej break;
95 1.3 thorpej default:
96 1.3 thorpej dev = CONSDEV_PC;
97 1.3 thorpej break;
98 1.3 thorpej }
99 1.3 thorpej return (iodevname[iodev = dev]);
100 1.1 perry #else
101 1.3 thorpej return (iodevname[0]);
102 1.1 perry #endif
103 1.1 perry }
104 1.1 perry
105 1.3 thorpej static inline void
106 1.3 thorpej internal_putchar(c)
107 1.3 thorpej int c;
108 1.1 perry {
109 1.1 perry #ifdef SUPPORT_SERIAL
110 1.3 thorpej switch (iodev) {
111 1.3 thorpej case CONSDEV_PC:
112 1.1 perry #endif
113 1.3 thorpej conputc(c);
114 1.1 perry #ifdef SUPPORT_SERIAL
115 1.3 thorpej break;
116 1.3 thorpej case CONSDEV_COM0:
117 1.3 thorpej computc(c, 0);
118 1.3 thorpej break;
119 1.3 thorpej case CONSDEV_COM1:
120 1.3 thorpej computc(c, 1);
121 1.3 thorpej break;
122 1.3 thorpej }
123 1.1 perry #endif
124 1.1 perry }
125 1.1 perry
126 1.3 thorpej void
127 1.3 thorpej putchar(c)
128 1.3 thorpej int c;
129 1.1 perry {
130 1.3 thorpej if (c == '\n')
131 1.3 thorpej internal_putchar('\r');
132 1.3 thorpej internal_putchar(c);
133 1.1 perry }
134 1.1 perry
135 1.3 thorpej int
136 1.3 thorpej getchar()
137 1.3 thorpej {
138 1.1 perry #ifdef SUPPORT_SERIAL
139 1.3 thorpej switch (iodev) {
140 1.4 drochner default: /* to make gcc -Wall happy... */
141 1.3 thorpej case CONSDEV_PC:
142 1.1 perry #endif
143 1.3 thorpej return (congetc());
144 1.1 perry #ifdef SUPPORT_SERIAL
145 1.3 thorpej case CONSDEV_COM0:
146 1.3 thorpej return (comgetc(0));
147 1.3 thorpej case CONSDEV_COM1:
148 1.3 thorpej return (comgetc(1));
149 1.3 thorpej }
150 1.1 perry #endif
151 1.1 perry }
152 1.1 perry
153 1.3 thorpej int
154 1.3 thorpej iskey()
155 1.3 thorpej {
156 1.1 perry #ifdef SUPPORT_SERIAL
157 1.3 thorpej switch (iodev) {
158 1.4 drochner default: /* to make gcc -Wall happy... */
159 1.3 thorpej case CONSDEV_PC:
160 1.1 perry #endif
161 1.3 thorpej return (coniskey());
162 1.1 perry #ifdef SUPPORT_SERIAL
163 1.3 thorpej case CONSDEV_COM0:
164 1.3 thorpej return (!!(comstatus(0) & 0x0100));
165 1.3 thorpej case CONSDEV_COM1:
166 1.3 thorpej return (!!(comstatus(1) & 0x0100));
167 1.3 thorpej }
168 1.1 perry #endif
169 1.1 perry }
170