pcio.c revision 1.3 1 1.3 thorpej /* $NetBSD: pcio.c,v 1.3 1997/03/22 01:48:37 thorpej 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.3 thorpej * console I/O needs lowlevel routines from conio.S and comio.S
37 1.3 thorpej */
38 1.1 perry
39 1.1 perry #include <lib/libsa/stand.h>
40 1.1 perry
41 1.1 perry #include "libi386.h"
42 1.1 perry
43 1.1 perry extern void conputc __P((int));
44 1.1 perry extern int congetc __P((void));
45 1.1 perry extern int coniskey __P((void));
46 1.1 perry
47 1.1 perry #ifdef SUPPORT_SERIAL
48 1.2 perry extern int computc __P((int, int));
49 1.2 perry extern int comgetc __P((int));
50 1.2 perry extern int comstatus __P((int));
51 1.1 perry
52 1.3 thorpej static int iodev;
53 1.1 perry #endif
54 1.1 perry
55 1.3 thorpej static char *iodevname[] = {
56 1.3 thorpej "pc",
57 1.1 perry #ifdef SUPPORT_SERIAL
58 1.3 thorpej "com0",
59 1.3 thorpej "com1"
60 1.1 perry #endif
61 1.1 perry };
62 1.1 perry
63 1.3 thorpej char *
64 1.3 thorpej initio(dev)
65 1.3 thorpej int dev;
66 1.1 perry {
67 1.1 perry #ifdef SUPPORT_SERIAL
68 1.3 thorpej switch (dev) {
69 1.3 thorpej case CONSDEV_AUTO:
70 1.3 thorpej /*
71 1.3 thorpej * serial console must have hardware handshake! check: 1.
72 1.3 thorpej * character output without error 2. status bits for modem
73 1.3 thorpej * ready set (status seems only useful after character
74 1.3 thorpej * output)
75 1.3 thorpej */
76 1.3 thorpej cominit(0);
77 1.3 thorpej if (!(computc(' ', 0) & 0x80) && (comstatus(0) & 0x00b0))
78 1.3 thorpej dev = CONSDEV_COM0;
79 1.3 thorpej else {
80 1.3 thorpej cominit(1);
81 1.3 thorpej if (!(computc(' ', 1) & 0x80) && (comstatus(1) & 0x00b0))
82 1.3 thorpej dev = CONSDEV_COM1;
83 1.3 thorpej else
84 1.3 thorpej dev = CONSDEV_PC;
85 1.3 thorpej }
86 1.3 thorpej break;
87 1.3 thorpej case CONSDEV_COM0:
88 1.3 thorpej cominit(0);
89 1.3 thorpej break;
90 1.3 thorpej case CONSDEV_COM1:
91 1.3 thorpej cominit(1);
92 1.3 thorpej break;
93 1.3 thorpej default:
94 1.3 thorpej dev = CONSDEV_PC;
95 1.3 thorpej break;
96 1.3 thorpej }
97 1.3 thorpej return (iodevname[iodev = dev]);
98 1.1 perry #else
99 1.3 thorpej return (iodevname[0]);
100 1.1 perry #endif
101 1.1 perry }
102 1.1 perry
103 1.3 thorpej static inline void
104 1.3 thorpej internal_putchar(c)
105 1.3 thorpej int c;
106 1.1 perry {
107 1.1 perry #ifdef SUPPORT_SERIAL
108 1.3 thorpej switch (iodev) {
109 1.3 thorpej case CONSDEV_PC:
110 1.1 perry #endif
111 1.3 thorpej conputc(c);
112 1.1 perry #ifdef SUPPORT_SERIAL
113 1.3 thorpej break;
114 1.3 thorpej case CONSDEV_COM0:
115 1.3 thorpej computc(c, 0);
116 1.3 thorpej break;
117 1.3 thorpej case CONSDEV_COM1:
118 1.3 thorpej computc(c, 1);
119 1.3 thorpej break;
120 1.3 thorpej }
121 1.1 perry #endif
122 1.1 perry }
123 1.1 perry
124 1.3 thorpej void
125 1.3 thorpej putchar(c)
126 1.3 thorpej int c;
127 1.1 perry {
128 1.3 thorpej if (c == '\n')
129 1.3 thorpej internal_putchar('\r');
130 1.3 thorpej internal_putchar(c);
131 1.1 perry }
132 1.1 perry
133 1.3 thorpej int
134 1.3 thorpej getchar()
135 1.3 thorpej {
136 1.1 perry #ifdef SUPPORT_SERIAL
137 1.3 thorpej switch (iodev) {
138 1.3 thorpej case CONSDEV_PC:
139 1.1 perry #endif
140 1.3 thorpej return (congetc());
141 1.1 perry #ifdef SUPPORT_SERIAL
142 1.3 thorpej case CONSDEV_COM0:
143 1.3 thorpej return (comgetc(0));
144 1.3 thorpej case CONSDEV_COM1:
145 1.3 thorpej return (comgetc(1));
146 1.3 thorpej }
147 1.1 perry #endif
148 1.1 perry }
149 1.1 perry
150 1.3 thorpej int
151 1.3 thorpej iskey()
152 1.3 thorpej {
153 1.1 perry #ifdef SUPPORT_SERIAL
154 1.3 thorpej switch (iodev) {
155 1.3 thorpej case CONSDEV_PC:
156 1.1 perry #endif
157 1.3 thorpej return (coniskey());
158 1.1 perry #ifdef SUPPORT_SERIAL
159 1.3 thorpej case CONSDEV_COM0:
160 1.3 thorpej return (!!(comstatus(0) & 0x0100));
161 1.3 thorpej case CONSDEV_COM1:
162 1.3 thorpej return (!!(comstatus(1) & 0x0100));
163 1.3 thorpej }
164 1.1 perry #endif
165 1.1 perry }
166