Home | History | Annotate | Line # | Download | only in lib
pcio.c revision 1.2
      1  1.2  perry /*	$NetBSD: pcio.c,v 1.2 1997/03/15 22:15:49 perry 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.1  perry /* console I/O
     36  1.1  perry  needs lowlevel routines from conio.S and comio.S
     37  1.1  perry */
     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.1  perry static int iodev;
     53  1.1  perry #endif
     54  1.1  perry 
     55  1.1  perry static char *iodevname[] = {
     56  1.1  perry     "pc",
     57  1.1  perry #ifdef SUPPORT_SERIAL
     58  1.1  perry     "com0",
     59  1.1  perry     "com1"
     60  1.1  perry #endif
     61  1.1  perry };
     62  1.1  perry 
     63  1.1  perry char *initio(dev)
     64  1.1  perry int dev;
     65  1.1  perry {
     66  1.1  perry #ifdef SUPPORT_SERIAL
     67  1.1  perry   switch(dev){
     68  1.1  perry     case CONSDEV_AUTO:
     69  1.1  perry       /* serial console must have hardware handshake!
     70  1.1  perry        check: 1. character output without error
     71  1.1  perry               2. status bits for modem ready set
     72  1.1  perry        (status seems only useful after character output)
     73  1.1  perry        */
     74  1.1  perry       cominit(0);
     75  1.1  perry       if(!(computc(' ', 0) & 0x80) && (comstatus(0) & 0x00b0))
     76  1.2  perry 	dev = CONSDEV_COM0;
     77  1.1  perry       else {
     78  1.1  perry 	cominit(1);
     79  1.1  perry 	if(!(computc(' ', 1) & 0x80) && (comstatus(1) & 0x00b0))
     80  1.2  perry 	  dev = CONSDEV_COM1;
     81  1.1  perry 	else
     82  1.2  perry 	  dev = CONSDEV_PC;
     83  1.1  perry       }
     84  1.1  perry       break;
     85  1.1  perry     case CONSDEV_COM0: cominit(0); break;
     86  1.1  perry     case CONSDEV_COM1: cominit(1); break;
     87  1.2  perry     default: dev = CONSDEV_PC; break;
     88  1.1  perry   }
     89  1.1  perry   return(iodevname[iodev = dev]);
     90  1.1  perry #else
     91  1.1  perry   return(iodevname[0]);
     92  1.1  perry #endif
     93  1.1  perry }
     94  1.1  perry 
     95  1.1  perry static inline void internal_putchar(c)
     96  1.1  perry int c;
     97  1.1  perry {
     98  1.1  perry #ifdef SUPPORT_SERIAL
     99  1.1  perry   switch(iodev){
    100  1.2  perry     case CONSDEV_PC:
    101  1.1  perry #endif
    102  1.1  perry       conputc(c);
    103  1.1  perry #ifdef SUPPORT_SERIAL
    104  1.1  perry       break;
    105  1.2  perry     case CONSDEV_COM0: computc(c, 0); break;
    106  1.2  perry     case CONSDEV_COM1: computc(c, 1); break;
    107  1.1  perry   }
    108  1.1  perry #endif
    109  1.1  perry }
    110  1.1  perry 
    111  1.1  perry void putchar(c)
    112  1.1  perry int c;
    113  1.1  perry {
    114  1.1  perry   if(c=='\n')
    115  1.1  perry     internal_putchar('\r');
    116  1.1  perry   internal_putchar(c);
    117  1.1  perry }
    118  1.1  perry 
    119  1.1  perry int getchar(){
    120  1.1  perry #ifdef SUPPORT_SERIAL
    121  1.1  perry   switch(iodev){
    122  1.2  perry     case CONSDEV_PC:
    123  1.1  perry #endif
    124  1.1  perry       return(congetc());
    125  1.1  perry #ifdef SUPPORT_SERIAL
    126  1.2  perry     case CONSDEV_COM0: return(comgetc(0));
    127  1.2  perry     case CONSDEV_COM1: return(comgetc(1));
    128  1.1  perry   }
    129  1.1  perry #endif
    130  1.1  perry }
    131  1.1  perry 
    132  1.1  perry int iskey(){
    133  1.1  perry #ifdef SUPPORT_SERIAL
    134  1.1  perry   switch(iodev){
    135  1.2  perry     case CONSDEV_PC:
    136  1.1  perry #endif
    137  1.1  perry       return(coniskey());
    138  1.1  perry #ifdef SUPPORT_SERIAL
    139  1.2  perry     case CONSDEV_COM0: return(!!(comstatus(0) & 0x0100));
    140  1.2  perry     case CONSDEV_COM1: return(!!(comstatus(1) & 0x0100));
    141  1.1  perry   }
    142  1.1  perry #endif
    143  1.1  perry }
    144