Home | History | Annotate | Line # | Download | only in include
pio.h revision 1.8
      1 /*	$NetBSD: pio.h,v 1.8 1994/10/27 04:16:16 cgd Exp $	*/
      2 
      3 /*
      4  * Copyright (c) 1993 Charles Hannum.
      5  * All rights reserved.
      6  *
      7  * Redistribution and use in source and binary forms, with or without
      8  * modification, are permitted provided that the following conditions
      9  * are met:
     10  * 1. Redistributions of source code must retain the above copyright
     11  *    notice, this list of conditions and the following disclaimer.
     12  * 2. Redistributions in binary form must reproduce the above copyright
     13  *    notice, this list of conditions and the following disclaimer in the
     14  *    documentation and/or other materials provided with the distribution.
     15  * 3. All advertising materials mentioning features or use of this software
     16  *    must display the following acknowledgement:
     17  *      This product includes software developed by Charles Hannum.
     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 /*
     34  * Functions to provide access to i386 programmed I/O instructions.
     35  */
     36 
     37 static __inline u_char
     38 inb(u_short port)
     39 {
     40 	u_char	data;
     41 	__asm __volatile("inb %1,%0" : "=a" (data) : "d" (port));
     42 	return data;
     43 }
     44 
     45 static __inline void
     46 insb(u_short port, void *addr, int cnt)
     47 {
     48 	__asm __volatile("cld\n\trepne\n\tinsb" :
     49 			 : "d" (port), "D" (addr), "c" (cnt) : "%edi", "%ecx", "memory");
     50 }
     51 
     52 static __inline u_short
     53 inw(u_short port)
     54 {
     55 	u_short	data;
     56 	__asm __volatile("inw %1,%0" : "=a" (data) : "d" (port));
     57 	return data;
     58 }
     59 
     60 static __inline void
     61 insw(u_short port, void *addr, int cnt)
     62 {
     63 	__asm __volatile("cld\n\trepne\n\tinsw" :
     64 			 : "d" (port), "D" (addr), "c" (cnt) : "%edi", "%ecx", "memory");
     65 }
     66 
     67 static __inline u_int
     68 inl(u_short port)
     69 {
     70 	u_int	data;
     71 	__asm __volatile("inl %1,%0" : "=a" (data) : "d" (port));
     72 	return data;
     73 }
     74 
     75 static __inline void
     76 insl(u_short port, void *addr, int cnt)
     77 {
     78 	__asm __volatile("cld\n\trepne\n\tinsl" :
     79 			 : "d" (port), "D" (addr), "c" (cnt) : "%edi", "%ecx", "memory");
     80 }
     81 
     82 static __inline void
     83 outb(u_short port, u_char data)
     84 {
     85 	__asm __volatile("outb %0,%1" : : "a" (data), "d" (port));
     86 }
     87 
     88 static __inline void
     89 outsb(u_short port, void *addr, int cnt)
     90 {
     91 	__asm __volatile("cld\n\trepne\n\toutsb" :
     92 			 : "d" (port), "S" (addr), "c" (cnt) : "%esi", "%ecx");
     93 }
     94 
     95 static __inline void
     96 outw(u_short port, u_short data)
     97 {
     98 	__asm __volatile("outw %0,%1" : : "a" (data), "d" (port));
     99 }
    100 
    101 static __inline void
    102 outsw(u_short port, void *addr, int cnt)
    103 {
    104 	__asm __volatile("cld\n\trepne\n\toutsw" :
    105 			 : "d" (port), "S" (addr), "c" (cnt) : "%esi", "%ecx");
    106 }
    107 
    108 static __inline void
    109 outl(u_short port, u_int data)
    110 {
    111 	__asm __volatile("outl %0,%1" : : "a" (data), "d" (port));
    112 }
    113 
    114 static __inline void
    115 outsl(u_short port, void *addr, int cnt)
    116 {
    117 	__asm __volatile("cld\n\trepne\n\toutsl" :
    118 			 : "d" (port), "S" (addr), "c" (cnt) : "%esi", "%ecx");
    119 }
    120