2.9
[glibc/nacl-glibc.git] / sysdeps / mach / hurd / i386 / sys / io.h
blob49ac9985a96e78be24da9f4c089f1a848cca7546
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.
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.
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.
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. */
20 #ifndef _SYS_IO_H
21 #define _SYS_IO_H 1
23 #include <features.h>
25 __BEGIN_DECLS
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;
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;
38 #if defined __GNUC__ && __GNUC__ >= 2
40 static __inline unsigned char
41 inb (unsigned short int port)
43 unsigned char _v;
45 __asm__ __volatile__ ("inb %w1,%0":"=a" (_v):"Nd" (port));
46 return _v;
49 static __inline unsigned char
50 inb_p (unsigned short int port)
52 unsigned char _v;
54 __asm__ __volatile__ ("inb %w1,%0\noutb %%al,$0x80":"=a" (_v):"Nd" (port));
55 return _v;
58 static __inline unsigned short int
59 inw (unsigned short int port)
61 unsigned short _v;
63 __asm__ __volatile__ ("inw %w1,%0":"=a" (_v):"Nd" (port));
64 return _v;
67 static __inline unsigned short int
68 inw_p (unsigned short int port)
70 unsigned short int _v;
72 __asm__ __volatile__ ("inw %w1,%0\noutb %%al,$0x80":"=a" (_v):"Nd" (port));
73 return _v;
76 static __inline unsigned int
77 inl (unsigned short int port)
79 unsigned int _v;
81 __asm__ __volatile__ ("inl %w1,%0":"=a" (_v):"Nd" (port));
82 return _v;
85 static __inline unsigned int
86 inl_p (unsigned short int port)
88 unsigned int _v;
89 __asm__ __volatile__ ("inl %w1,%0\noutb %%al,$0x80":"=a" (_v):"Nd" (port));
90 return _v;
93 static __inline void
94 outb (unsigned char value, unsigned short int port)
96 __asm__ __volatile__ ("outb %b0,%w1": :"a" (value), "Nd" (port));
99 static __inline void
100 outb_p (unsigned char value, unsigned short int port)
102 __asm__ __volatile__ ("outb %b0,%w1\noutb %%al,$0x80": :"a" (value),
103 "Nd" (port));
106 static __inline void
107 outw (unsigned short int value, unsigned short int port)
109 __asm__ __volatile__ ("outw %w0,%w1": :"a" (value), "Nd" (port));
113 static __inline void
114 outw_p (unsigned short int value, unsigned short int port)
116 __asm__ __volatile__ ("outw %w0,%w1\noutb %%al,$0x80": :"a" (value),
117 "Nd" (port));
120 static __inline void
121 outl (unsigned int value, unsigned short int port)
123 __asm__ __volatile__ ("outl %0,%w1": :"a" (value), "Nd" (port));
126 static __inline void
127 outl_p (unsigned int value, unsigned short int port)
129 __asm__ __volatile__ ("outl %0,%w1\noutb %%al,$0x80": :"a" (value),
130 "Nd" (port));
133 static __inline void
134 insb (unsigned short int port, void *addr, unsigned long int count)
136 __asm__ __volatile__ ("cld ; rep ; insb":"=D" (addr),
137 "=c" (count):"d" (port), "0" (addr), "1" (count));
140 static __inline void
141 insw (unsigned short int port, void *addr, unsigned long int count)
143 __asm__ __volatile__ ("cld ; rep ; insw":"=D" (addr),
144 "=c" (count):"d" (port), "0" (addr), "1" (count));
147 static __inline void
148 insl (unsigned short int port, void *addr, unsigned long int count)
150 __asm__ __volatile__ ("cld ; rep ; insl":"=D" (addr),
151 "=c" (count):"d" (port), "0" (addr), "1" (count));
154 static __inline void
155 outsb (unsigned short int port, const void *addr, unsigned long int count)
157 __asm__ __volatile__ ("cld ; rep ; outsb":"=S" (addr),
158 "=c" (count):"d" (port), "0" (addr), "1" (count));
161 static __inline void
162 outsw (unsigned short int port, const void *addr, unsigned long int count)
164 __asm__ __volatile__ ("cld ; rep ; outsw":"=S" (addr),
165 "=c" (count):"d" (port), "0" (addr), "1" (count));
168 static __inline void
169 outsl (unsigned short int port, const void *addr, unsigned long int count)
171 __asm__ __volatile__ ("cld ; rep ; outsl":"=S" (addr),
172 "=c" (count):"d" (port), "0" (addr), "1" (count));
175 #endif /* GNU C */
177 __END_DECLS
178 #endif /* _SYS_IO_H */