1 /* Copyright (C) 1996, 2000, 2002 Free Software Foundation, Inc.
2 This file is part of the GNU C Library.
4 The GNU C Library is free software; you can redistribute it and/or
5 modify it under the terms of the GNU Lesser General Public
6 License as published by the Free Software Foundation; either
7 version 2.1 of the License, or (at your option) any later version.
9 The GNU C Library is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 Lesser General Public License for more details.
14 You should have received a copy of the GNU Lesser General Public
15 License along with the GNU C Library; if not, write to the Free
16 Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
26 /* If TURN_ON is TRUE, request for permission to do direct i/o on the
27 port numbers in the range [FROM,FROM+NUM-1]. Otherwise, turn I/O
28 permission off for that range. This call requires root privileges.
30 Portability note: not all Linux platforms support this call. Most
31 platforms based on the PC I/O architecture probably will, however.
32 E.g., Linux/Alpha for Alpha PCs supports this. */
33 extern int ioperm (unsigned long int __from, unsigned long int __num,
34 int __turn_on) __THROW;
35 libc_hidden_proto(ioperm)
37 /* Set the I/O privilege level to LEVEL. If LEVEL>3, permission to
38 access any I/O port is granted. This call requires root
40 extern int iopl (int __level) __THROW;
42 #if defined __GNUC__ && __GNUC__ >= 2
44 static __inline unsigned char
45 inb (unsigned short int port)
49 __asm__ __volatile__ ("inb %w1,%0":"=a" (_v):"Nd" (port));
53 static __inline unsigned char
54 inb_p (unsigned short int port)
58 __asm__ __volatile__ ("inb %w1,%0\noutb %%al,$0x80":"=a" (_v):"Nd" (port));
62 static __inline unsigned short int
63 inw (unsigned short int port)
67 __asm__ __volatile__ ("inw %w1,%0":"=a" (_v):"Nd" (port));
71 static __inline unsigned short int
72 inw_p (unsigned short int port)
74 unsigned short int _v;
76 __asm__ __volatile__ ("inw %w1,%0\noutb %%al,$0x80":"=a" (_v):"Nd" (port));
80 static __inline unsigned int
81 inl (unsigned short int port)
85 __asm__ __volatile__ ("inl %w1,%0":"=a" (_v):"Nd" (port));
89 static __inline unsigned int
90 inl_p (unsigned short int port)
93 __asm__ __volatile__ ("inl %w1,%0\noutb %%al,$0x80":"=a" (_v):"Nd" (port));
98 outb (unsigned char value, unsigned short int port)
100 __asm__ __volatile__ ("outb %b0,%w1": :"a" (value), "Nd" (port));
104 outb_p (unsigned char value, unsigned short int port)
106 __asm__ __volatile__ ("outb %b0,%w1\noutb %%al,$0x80": :"a" (value),
111 outw (unsigned short int value, unsigned short int port)
113 __asm__ __volatile__ ("outw %w0,%w1": :"a" (value), "Nd" (port));
118 outw_p (unsigned short int value, unsigned short int port)
120 __asm__ __volatile__ ("outw %w0,%w1\noutb %%al,$0x80": :"a" (value),
125 outl (unsigned int value, unsigned short int port)
127 __asm__ __volatile__ ("outl %0,%w1": :"a" (value), "Nd" (port));
131 outl_p (unsigned int value, unsigned short int port)
133 __asm__ __volatile__ ("outl %0,%w1\noutb %%al,$0x80": :"a" (value),
138 insb (unsigned short int port, void *addr, unsigned long int count)
140 __asm__ __volatile__ ("cld ; rep ; insb":"=D" (addr),
141 "=c" (count):"d" (port), "0" (addr), "1" (count));
145 insw (unsigned short int port, void *addr, unsigned long int count)
147 __asm__ __volatile__ ("cld ; rep ; insw":"=D" (addr),
148 "=c" (count):"d" (port), "0" (addr), "1" (count));
152 insl (unsigned short int port, void *addr, unsigned long int count)
154 __asm__ __volatile__ ("cld ; rep ; insl":"=D" (addr),
155 "=c" (count):"d" (port), "0" (addr), "1" (count));
159 outsb (unsigned short int port, const void *addr, unsigned long int count)
161 __asm__ __volatile__ ("cld ; rep ; outsb":"=S" (addr),
162 "=c" (count):"d" (port), "0" (addr), "1" (count));
166 outsw (unsigned short int port, const void *addr, unsigned long int count)
168 __asm__ __volatile__ ("cld ; rep ; outsw":"=S" (addr),
169 "=c" (count):"d" (port), "0" (addr), "1" (count));
173 outsl (unsigned short int port, const void *addr, unsigned long int count)
175 __asm__ __volatile__ ("cld ; rep ; outsl":"=S" (addr),
176 "=c" (count):"d" (port), "0" (addr), "1" (count));
182 #endif /* _SYS_IO_H */