pio.h revision 1.9 1 1.9 mycroft /* $NetBSD: pio.h,v 1.9 1994/11/18 22:18:35 mycroft Exp $ */
2 1.8 cgd
3 1.4 mycroft /*
4 1.4 mycroft * Copyright (c) 1993 Charles Hannum.
5 1.4 mycroft * All rights reserved.
6 1.3 cgd *
7 1.4 mycroft * Redistribution and use in source and binary forms, with or without
8 1.4 mycroft * modification, are permitted provided that the following conditions
9 1.4 mycroft * are met:
10 1.4 mycroft * 1. Redistributions of source code must retain the above copyright
11 1.4 mycroft * notice, this list of conditions and the following disclaimer.
12 1.4 mycroft * 2. Redistributions in binary form must reproduce the above copyright
13 1.4 mycroft * notice, this list of conditions and the following disclaimer in the
14 1.4 mycroft * documentation and/or other materials provided with the distribution.
15 1.4 mycroft * 3. All advertising materials mentioning features or use of this software
16 1.4 mycroft * must display the following acknowledgement:
17 1.4 mycroft * This product includes software developed by Charles Hannum.
18 1.4 mycroft * 4. The name of the author may not be used to endorse or promote products
19 1.7 jtc * derived from this software without specific prior written permission
20 1.2 cgd *
21 1.4 mycroft * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
22 1.4 mycroft * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
23 1.4 mycroft * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
24 1.4 mycroft * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
25 1.4 mycroft * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
26 1.4 mycroft * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
27 1.4 mycroft * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
28 1.4 mycroft * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
29 1.4 mycroft * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
30 1.4 mycroft * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31 1.1 cgd */
32 1.1 cgd
33 1.3 cgd /*
34 1.4 mycroft * Functions to provide access to i386 programmed I/O instructions.
35 1.3 cgd */
36 1.1 cgd
37 1.4 mycroft static __inline u_char
38 1.9 mycroft inb(int port)
39 1.4 mycroft {
40 1.4 mycroft u_char data;
41 1.9 mycroft __asm __volatile("inb %%dx,%0" : "=a" (data) : "d" (port));
42 1.4 mycroft return data;
43 1.4 mycroft }
44 1.4 mycroft
45 1.4 mycroft static __inline void
46 1.9 mycroft insb(int port, void *addr, int cnt)
47 1.4 mycroft {
48 1.6 mycroft __asm __volatile("cld\n\trepne\n\tinsb" :
49 1.5 deraadt : "d" (port), "D" (addr), "c" (cnt) : "%edi", "%ecx", "memory");
50 1.4 mycroft }
51 1.4 mycroft
52 1.4 mycroft static __inline u_short
53 1.9 mycroft inw(int port)
54 1.4 mycroft {
55 1.4 mycroft u_short data;
56 1.9 mycroft __asm __volatile("inw %%dx,%0" : "=a" (data) : "d" (port));
57 1.4 mycroft return data;
58 1.4 mycroft }
59 1.4 mycroft
60 1.4 mycroft static __inline void
61 1.9 mycroft insw(int port, void *addr, int cnt)
62 1.4 mycroft {
63 1.6 mycroft __asm __volatile("cld\n\trepne\n\tinsw" :
64 1.5 deraadt : "d" (port), "D" (addr), "c" (cnt) : "%edi", "%ecx", "memory");
65 1.4 mycroft }
66 1.4 mycroft
67 1.4 mycroft static __inline u_int
68 1.9 mycroft inl(int port)
69 1.4 mycroft {
70 1.4 mycroft u_int data;
71 1.9 mycroft __asm __volatile("inl %%dx,%0" : "=a" (data) : "d" (port));
72 1.4 mycroft return data;
73 1.4 mycroft }
74 1.4 mycroft
75 1.4 mycroft static __inline void
76 1.9 mycroft insl(int port, void *addr, int cnt)
77 1.4 mycroft {
78 1.6 mycroft __asm __volatile("cld\n\trepne\n\tinsl" :
79 1.5 deraadt : "d" (port), "D" (addr), "c" (cnt) : "%edi", "%ecx", "memory");
80 1.4 mycroft }
81 1.4 mycroft
82 1.4 mycroft static __inline void
83 1.9 mycroft outb(int port, u_char data)
84 1.4 mycroft {
85 1.9 mycroft __asm __volatile("outb %0,%%dx" : : "a" (data), "d" (port));
86 1.4 mycroft }
87 1.4 mycroft
88 1.4 mycroft static __inline void
89 1.9 mycroft outsb(int port, void *addr, int cnt)
90 1.4 mycroft {
91 1.6 mycroft __asm __volatile("cld\n\trepne\n\toutsb" :
92 1.5 deraadt : "d" (port), "S" (addr), "c" (cnt) : "%esi", "%ecx");
93 1.4 mycroft }
94 1.4 mycroft
95 1.4 mycroft static __inline void
96 1.9 mycroft outw(int port, u_short data)
97 1.4 mycroft {
98 1.9 mycroft __asm __volatile("outw %0,%%dx" : : "a" (data), "d" (port));
99 1.4 mycroft }
100 1.4 mycroft
101 1.4 mycroft static __inline void
102 1.9 mycroft outsw(int port, void *addr, int cnt)
103 1.4 mycroft {
104 1.6 mycroft __asm __volatile("cld\n\trepne\n\toutsw" :
105 1.5 deraadt : "d" (port), "S" (addr), "c" (cnt) : "%esi", "%ecx");
106 1.4 mycroft }
107 1.4 mycroft
108 1.4 mycroft static __inline void
109 1.9 mycroft outl(int port, u_int data)
110 1.4 mycroft {
111 1.9 mycroft __asm __volatile("outl %0,%%dx" : : "a" (data), "d" (port));
112 1.4 mycroft }
113 1.4 mycroft
114 1.4 mycroft static __inline void
115 1.9 mycroft outsl(int port, void *addr, int cnt)
116 1.4 mycroft {
117 1.6 mycroft __asm __volatile("cld\n\trepne\n\toutsl" :
118 1.5 deraadt : "d" (port), "S" (addr), "c" (cnt) : "%esi", "%ecx");
119 1.4 mycroft }
120