1997-06-13 17:41:20 +04:00
|
|
|
/* $NetBSD: pcio.c,v 1.4 1997/06/13 13:41:20 drochner Exp $ */
|
1997-03-14 05:40:32 +03:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Copyright (c) 1996
|
|
|
|
* Matthias Drochner. All rights reserved.
|
|
|
|
*
|
|
|
|
* Redistribution and use in source and binary forms, with or without
|
|
|
|
* modification, are permitted provided that the following conditions
|
|
|
|
* are met:
|
|
|
|
* 1. Redistributions of source code must retain the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer.
|
|
|
|
* 2. Redistributions in binary form must reproduce the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer in the
|
|
|
|
* documentation and/or other materials provided with the distribution.
|
|
|
|
* 3. All advertising materials mentioning features or use of this software
|
|
|
|
* must display the following acknowledgement:
|
|
|
|
* This product includes software developed for the NetBSD Project
|
|
|
|
* by Matthias Drochner.
|
|
|
|
* 4. The name of the author may not be used to endorse or promote products
|
|
|
|
* derived from this software without specific prior written permission.
|
|
|
|
*
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
|
|
|
|
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
|
|
|
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
|
|
|
|
* IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
|
|
|
|
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
|
|
|
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
|
|
|
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
|
|
|
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
|
|
|
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
|
|
|
|
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
1997-03-22 04:48:27 +03:00
|
|
|
/*
|
1997-06-13 17:41:20 +04:00
|
|
|
* console I/O
|
|
|
|
* needs lowlevel routines from conio.S and comio.S
|
1997-03-22 04:48:27 +03:00
|
|
|
*/
|
1997-03-14 05:40:32 +03:00
|
|
|
|
|
|
|
#include <lib/libsa/stand.h>
|
|
|
|
|
|
|
|
#include "libi386.h"
|
|
|
|
|
|
|
|
extern void conputc __P((int));
|
|
|
|
extern int congetc __P((void));
|
|
|
|
extern int coniskey __P((void));
|
|
|
|
|
|
|
|
#ifdef SUPPORT_SERIAL
|
1997-06-13 17:41:20 +04:00
|
|
|
extern void cominit __P((int));
|
1997-03-16 01:15:49 +03:00
|
|
|
extern int computc __P((int, int));
|
|
|
|
extern int comgetc __P((int));
|
|
|
|
extern int comstatus __P((int));
|
1997-03-14 05:40:32 +03:00
|
|
|
|
1997-03-22 04:48:27 +03:00
|
|
|
static int iodev;
|
1997-03-14 05:40:32 +03:00
|
|
|
#endif
|
|
|
|
|
1997-03-22 04:48:27 +03:00
|
|
|
static char *iodevname[] = {
|
|
|
|
"pc",
|
1997-03-14 05:40:32 +03:00
|
|
|
#ifdef SUPPORT_SERIAL
|
1997-03-22 04:48:27 +03:00
|
|
|
"com0",
|
|
|
|
"com1"
|
1997-03-14 05:40:32 +03:00
|
|
|
#endif
|
|
|
|
};
|
|
|
|
|
1997-03-22 04:48:27 +03:00
|
|
|
char *
|
|
|
|
initio(dev)
|
|
|
|
int dev;
|
1997-03-14 05:40:32 +03:00
|
|
|
{
|
|
|
|
#ifdef SUPPORT_SERIAL
|
1997-03-22 04:48:27 +03:00
|
|
|
switch (dev) {
|
|
|
|
case CONSDEV_AUTO:
|
|
|
|
/*
|
|
|
|
* serial console must have hardware handshake! check: 1.
|
|
|
|
* character output without error 2. status bits for modem
|
|
|
|
* ready set (status seems only useful after character
|
|
|
|
* output)
|
|
|
|
*/
|
|
|
|
cominit(0);
|
|
|
|
if (!(computc(' ', 0) & 0x80) && (comstatus(0) & 0x00b0))
|
|
|
|
dev = CONSDEV_COM0;
|
|
|
|
else {
|
|
|
|
cominit(1);
|
|
|
|
if (!(computc(' ', 1) & 0x80) && (comstatus(1) & 0x00b0))
|
|
|
|
dev = CONSDEV_COM1;
|
|
|
|
else
|
|
|
|
dev = CONSDEV_PC;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case CONSDEV_COM0:
|
|
|
|
cominit(0);
|
|
|
|
break;
|
|
|
|
case CONSDEV_COM1:
|
|
|
|
cominit(1);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
dev = CONSDEV_PC;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
return (iodevname[iodev = dev]);
|
1997-03-14 05:40:32 +03:00
|
|
|
#else
|
1997-03-22 04:48:27 +03:00
|
|
|
return (iodevname[0]);
|
1997-03-14 05:40:32 +03:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
1997-03-22 04:48:27 +03:00
|
|
|
static inline void
|
|
|
|
internal_putchar(c)
|
|
|
|
int c;
|
1997-03-14 05:40:32 +03:00
|
|
|
{
|
|
|
|
#ifdef SUPPORT_SERIAL
|
1997-03-22 04:48:27 +03:00
|
|
|
switch (iodev) {
|
|
|
|
case CONSDEV_PC:
|
1997-03-14 05:40:32 +03:00
|
|
|
#endif
|
1997-03-22 04:48:27 +03:00
|
|
|
conputc(c);
|
1997-03-14 05:40:32 +03:00
|
|
|
#ifdef SUPPORT_SERIAL
|
1997-03-22 04:48:27 +03:00
|
|
|
break;
|
|
|
|
case CONSDEV_COM0:
|
|
|
|
computc(c, 0);
|
|
|
|
break;
|
|
|
|
case CONSDEV_COM1:
|
|
|
|
computc(c, 1);
|
|
|
|
break;
|
|
|
|
}
|
1997-03-14 05:40:32 +03:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
1997-03-22 04:48:27 +03:00
|
|
|
void
|
|
|
|
putchar(c)
|
|
|
|
int c;
|
1997-03-14 05:40:32 +03:00
|
|
|
{
|
1997-03-22 04:48:27 +03:00
|
|
|
if (c == '\n')
|
|
|
|
internal_putchar('\r');
|
|
|
|
internal_putchar(c);
|
1997-03-14 05:40:32 +03:00
|
|
|
}
|
|
|
|
|
1997-03-22 04:48:27 +03:00
|
|
|
int
|
|
|
|
getchar()
|
|
|
|
{
|
1997-03-14 05:40:32 +03:00
|
|
|
#ifdef SUPPORT_SERIAL
|
1997-03-22 04:48:27 +03:00
|
|
|
switch (iodev) {
|
1997-06-13 17:41:20 +04:00
|
|
|
default: /* to make gcc -Wall happy... */
|
1997-03-22 04:48:27 +03:00
|
|
|
case CONSDEV_PC:
|
1997-03-14 05:40:32 +03:00
|
|
|
#endif
|
1997-03-22 04:48:27 +03:00
|
|
|
return (congetc());
|
1997-03-14 05:40:32 +03:00
|
|
|
#ifdef SUPPORT_SERIAL
|
1997-03-22 04:48:27 +03:00
|
|
|
case CONSDEV_COM0:
|
|
|
|
return (comgetc(0));
|
|
|
|
case CONSDEV_COM1:
|
|
|
|
return (comgetc(1));
|
|
|
|
}
|
1997-03-14 05:40:32 +03:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
1997-03-22 04:48:27 +03:00
|
|
|
int
|
|
|
|
iskey()
|
|
|
|
{
|
1997-03-14 05:40:32 +03:00
|
|
|
#ifdef SUPPORT_SERIAL
|
1997-03-22 04:48:27 +03:00
|
|
|
switch (iodev) {
|
1997-06-13 17:41:20 +04:00
|
|
|
default: /* to make gcc -Wall happy... */
|
1997-03-22 04:48:27 +03:00
|
|
|
case CONSDEV_PC:
|
1997-03-14 05:40:32 +03:00
|
|
|
#endif
|
1997-03-22 04:48:27 +03:00
|
|
|
return (coniskey());
|
1997-03-14 05:40:32 +03:00
|
|
|
#ifdef SUPPORT_SERIAL
|
1997-03-22 04:48:27 +03:00
|
|
|
case CONSDEV_COM0:
|
|
|
|
return (!!(comstatus(0) & 0x0100));
|
|
|
|
case CONSDEV_COM1:
|
|
|
|
return (!!(comstatus(1) & 0x0100));
|
|
|
|
}
|
1997-03-14 05:40:32 +03:00
|
|
|
#endif
|
|
|
|
}
|