chiark / gitweb /
eglibc (2.11.3-4+deb6u3) squeeze-lts; urgency=medium
[eglibc.git] / sysdeps / mach / hurd / i386 / sys / io.h
1 /* Access to hardware i/o ports.  GNU/x86 version.
2    Copyright (C) 2002 Free Software Foundation, Inc.
3    This file is part of the GNU C Library.
4
5    The GNU C Library is free software; you can redistribute it and/or
6    modify it under the terms of the GNU Lesser General Public
7    License as published by the Free Software Foundation; either
8    version 2.1 of the License, or (at your option) any later version.
9
10    The GNU C Library is distributed in the hope that it will be useful,
11    but WITHOUT ANY WARRANTY; without even the implied warranty of
12    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13    Lesser General Public License for more details.
14
15    You should have received a copy of the GNU Lesser General Public
16    License along with the GNU C Library; if not, write to the Free
17    Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
18    02111-1307 USA.  */
19
20 #ifndef _SYS_IO_H
21 #define _SYS_IO_H       1
22
23 #include <features.h>
24
25 __BEGIN_DECLS
26
27 /* If TURN_ON is TRUE, request for permission to do direct i/o on the
28    port numbers in the range [FROM,FROM+NUM-1].  Otherwise, turn I/O
29    permission off for that range.  This call requires root privileges.  */
30 extern int ioperm (unsigned long int __from, unsigned long int __num,
31                    int __turn_on) __THROW;
32
33 /* Set the I/O privilege level to LEVEL.  If LEVEL>3, permission to
34    access any I/O port is granted.  This call requires root
35    privileges. */
36 extern int iopl (int __level) __THROW;
37
38 #if defined __GNUC__ && __GNUC__ >= 2
39
40 static __inline unsigned char
41 inb (unsigned short int port)
42 {
43   unsigned char _v;
44
45   __asm__ __volatile__ ("inb %w1,%0":"=a" (_v):"Nd" (port));
46   return _v;
47 }
48
49 static __inline unsigned char
50 inb_p (unsigned short int port)
51 {
52   unsigned char _v;
53
54   __asm__ __volatile__ ("inb %w1,%0\noutb %%al,$0x80":"=a" (_v):"Nd" (port));
55   return _v;
56 }
57
58 static __inline unsigned short int
59 inw (unsigned short int port)
60 {
61   unsigned short _v;
62
63   __asm__ __volatile__ ("inw %w1,%0":"=a" (_v):"Nd" (port));
64   return _v;
65 }
66
67 static __inline unsigned short int
68 inw_p (unsigned short int port)
69 {
70   unsigned short int _v;
71
72   __asm__ __volatile__ ("inw %w1,%0\noutb %%al,$0x80":"=a" (_v):"Nd" (port));
73   return _v;
74 }
75
76 static __inline unsigned int
77 inl (unsigned short int port)
78 {
79   unsigned int _v;
80
81   __asm__ __volatile__ ("inl %w1,%0":"=a" (_v):"Nd" (port));
82   return _v;
83 }
84
85 static __inline unsigned int
86 inl_p (unsigned short int port)
87 {
88   unsigned int _v;
89   __asm__ __volatile__ ("inl %w1,%0\noutb %%al,$0x80":"=a" (_v):"Nd" (port));
90   return _v;
91 }
92
93 static __inline void
94 outb (unsigned char value, unsigned short int port)
95 {
96   __asm__ __volatile__ ("outb %b0,%w1": :"a" (value), "Nd" (port));
97 }
98
99 static __inline void
100 outb_p (unsigned char value, unsigned short int port)
101 {
102   __asm__ __volatile__ ("outb %b0,%w1\noutb %%al,$0x80": :"a" (value),
103                         "Nd" (port));
104 }
105
106 static __inline void
107 outw (unsigned short int value, unsigned short int port)
108 {
109   __asm__ __volatile__ ("outw %w0,%w1": :"a" (value), "Nd" (port));
110
111 }
112
113 static __inline void
114 outw_p (unsigned short int value, unsigned short int port)
115 {
116   __asm__ __volatile__ ("outw %w0,%w1\noutb %%al,$0x80": :"a" (value),
117                         "Nd" (port));
118 }
119
120 static __inline void
121 outl (unsigned int value, unsigned short int port)
122 {
123   __asm__ __volatile__ ("outl %0,%w1": :"a" (value), "Nd" (port));
124 }
125
126 static __inline void
127 outl_p (unsigned int value, unsigned short int port)
128 {
129   __asm__ __volatile__ ("outl %0,%w1\noutb %%al,$0x80": :"a" (value),
130                         "Nd" (port));
131 }
132
133 static __inline void
134 insb (unsigned short int port, void *addr, unsigned long int count)
135 {
136   __asm__ __volatile__ ("cld ; rep ; insb":"=D" (addr),
137                         "=c" (count):"d" (port), "0" (addr), "1" (count));
138 }
139
140 static __inline void
141 insw (unsigned short int port, void *addr, unsigned long int count)
142 {
143   __asm__ __volatile__ ("cld ; rep ; insw":"=D" (addr),
144                         "=c" (count):"d" (port), "0" (addr), "1" (count));
145 }
146
147 static __inline void
148 insl (unsigned short int port, void *addr, unsigned long int count)
149 {
150   __asm__ __volatile__ ("cld ; rep ; insl":"=D" (addr),
151                         "=c" (count):"d" (port), "0" (addr), "1" (count));
152 }
153
154 static __inline void
155 outsb (unsigned short int port, const void *addr, unsigned long int count)
156 {
157   __asm__ __volatile__ ("cld ; rep ; outsb":"=S" (addr),
158                         "=c" (count):"d" (port), "0" (addr), "1" (count));
159 }
160
161 static __inline void
162 outsw (unsigned short int port, const void *addr, unsigned long int count)
163 {
164   __asm__ __volatile__ ("cld ; rep ; outsw":"=S" (addr),
165                         "=c" (count):"d" (port), "0" (addr), "1" (count));
166 }
167
168 static __inline void
169 outsl (unsigned short int port, const void *addr, unsigned long int count)
170 {
171   __asm__ __volatile__ ("cld ; rep ; outsl":"=S" (addr),
172                         "=c" (count):"d" (port), "0" (addr), "1" (count));
173 }
174
175 #endif  /* GNU C */
176
177 __END_DECLS
178 #endif /* _SYS_IO_H */