summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRich Felker <dalias@aerifal.cx>2012-11-18 19:31:58 -0500
committerRich Felker <dalias@aerifal.cx>2012-11-18 19:31:58 -0500
commit61aa6324af982b635f8c392640a4e8e450c4c6b4 (patch)
treeb17e98b2fd56ef4b11bca2d15007a2b3c8b7a90e
parentf54ac2446abac57cacebc64df78a5ef850045700 (diff)
downloadmusl-61aa6324af982b635f8c392640a4e8e450c4c6b4.tar.gz
add port io functions to sys/io.h
based on proposal by Isaac Dunham. nonexistance of bits/io.h will cause inclusion of sys/io.h to produce an error on archs that are not supposed to have it. this is probably the desired behavior, but the error message may be a bit unusual.
-rw-r--r--arch/i386/bits/io.h80
-rw-r--r--arch/x86_64/bits/io.h80
-rw-r--r--include/sys/io.h5
-rw-r--r--src/linux/ioperm.c3
-rw-r--r--src/linux/iopl.c3
5 files changed, 167 insertions, 4 deletions
diff --git a/arch/i386/bits/io.h b/arch/i386/bits/io.h
new file mode 100644
index 00000000..d26ea57b
--- /dev/null
+++ b/arch/i386/bits/io.h
@@ -0,0 +1,80 @@
+int iopl(int);
+int ioperm(unsigned long, unsigned long, int);
+
+static __inline void outb(unsigned char __val, unsigned short __port)
+{
+ __asm__ volatile ("outb %0,%1" : : "a" (__val), "dN" (__port));
+}
+
+static __inline void outw(unsigned short __val, unsigned short __port)
+{
+ __asm__ volatile ("outw %0,%1" : : "a" (__val), "dN" (__port));
+}
+
+static __inline void outl(unsigned int __val, unsigned short __port)
+{
+ __asm__ volatile ("outl %0,%1" : : "a" (__val), "dN" (__port));
+}
+
+static __inline unsigned char inb(unsigned short __port)
+{
+ unsigned char __val;
+ __asm__ volatile ("inb %1,%0" : "=a" (__val) : "dN" (__port));
+ return __val;
+}
+
+static __inline unsigned short inw(unsigned short __port)
+{
+ unsigned short __val;
+ __asm__ volatile ("inw %1,%0" : "=a" (__val) : "dN" (__port));
+ return __val;
+}
+
+static __inline unsigned int inl(unsigned short __port)
+{
+ unsigned int __val;
+ __asm__ volatile ("inl %1,%0" : "=a" (__val) : "dN" (__port));
+ return __val;
+}
+
+static __inline void outsb(unsigned short __port, const void *__buf, unsigned long __n)
+{
+ __asm__ volatile ("cld; rep; outsb"
+ : "+S" (__buf), "+c" (__n)
+ : "d" (__port));
+}
+
+static __inline void outsw(unsigned short __port, const void *__buf, unsigned long __n)
+{
+ __asm__ volatile ("cld; rep; outsw"
+ : "+S" (__buf), "+c" (__n)
+ : "d" (__port));
+}
+
+static __inline void outsl(unsigned short __port, const void *__buf, unsigned long __n)
+{
+ __asm__ volatile ("cld; rep; outsl"
+ : "+S" (__buf), "+c"(__n)
+ : "d" (__port));
+}
+
+static __inline void insb(unsigned short __port, void *__buf, unsigned long __n)
+{
+ __asm__ volatile ("cld; rep; insb"
+ : "+D" (__buf), "+c" (__n)
+ : "d" (__port));
+}
+
+static __inline void insw(unsigned short __port, void *__buf, unsigned long __n)
+{
+ __asm__ volatile ("cld; rep; insw"
+ : "+D" (__buf), "+c" (__n)
+ : "d" (__port));
+}
+
+static __inline void insl(unsigned short __port, void *__buf, unsigned long __n)
+{
+ __asm__ volatile ("cld; rep; insl"
+ : "+D" (__buf), "+c" (__n)
+ : "d" (__port));
+}
diff --git a/arch/x86_64/bits/io.h b/arch/x86_64/bits/io.h
new file mode 100644
index 00000000..d26ea57b
--- /dev/null
+++ b/arch/x86_64/bits/io.h
@@ -0,0 +1,80 @@
+int iopl(int);
+int ioperm(unsigned long, unsigned long, int);
+
+static __inline void outb(unsigned char __val, unsigned short __port)
+{
+ __asm__ volatile ("outb %0,%1" : : "a" (__val), "dN" (__port));
+}
+
+static __inline void outw(unsigned short __val, unsigned short __port)
+{
+ __asm__ volatile ("outw %0,%1" : : "a" (__val), "dN" (__port));
+}
+
+static __inline void outl(unsigned int __val, unsigned short __port)
+{
+ __asm__ volatile ("outl %0,%1" : : "a" (__val), "dN" (__port));
+}
+
+static __inline unsigned char inb(unsigned short __port)
+{
+ unsigned char __val;
+ __asm__ volatile ("inb %1,%0" : "=a" (__val) : "dN" (__port));
+ return __val;
+}
+
+static __inline unsigned short inw(unsigned short __port)
+{
+ unsigned short __val;
+ __asm__ volatile ("inw %1,%0" : "=a" (__val) : "dN" (__port));
+ return __val;
+}
+
+static __inline unsigned int inl(unsigned short __port)
+{
+ unsigned int __val;
+ __asm__ volatile ("inl %1,%0" : "=a" (__val) : "dN" (__port));
+ return __val;
+}
+
+static __inline void outsb(unsigned short __port, const void *__buf, unsigned long __n)
+{
+ __asm__ volatile ("cld; rep; outsb"
+ : "+S" (__buf), "+c" (__n)
+ : "d" (__port));
+}
+
+static __inline void outsw(unsigned short __port, const void *__buf, unsigned long __n)
+{
+ __asm__ volatile ("cld; rep; outsw"
+ : "+S" (__buf), "+c" (__n)
+ : "d" (__port));
+}
+
+static __inline void outsl(unsigned short __port, const void *__buf, unsigned long __n)
+{
+ __asm__ volatile ("cld; rep; outsl"
+ : "+S" (__buf), "+c"(__n)
+ : "d" (__port));
+}
+
+static __inline void insb(unsigned short __port, void *__buf, unsigned long __n)
+{
+ __asm__ volatile ("cld; rep; insb"
+ : "+D" (__buf), "+c" (__n)
+ : "d" (__port));
+}
+
+static __inline void insw(unsigned short __port, void *__buf, unsigned long __n)
+{
+ __asm__ volatile ("cld; rep; insw"
+ : "+D" (__buf), "+c" (__n)
+ : "d" (__port));
+}
+
+static __inline void insl(unsigned short __port, void *__buf, unsigned long __n)
+{
+ __asm__ volatile ("cld; rep; insl"
+ : "+D" (__buf), "+c" (__n)
+ : "d" (__port));
+}
diff --git a/include/sys/io.h b/include/sys/io.h
index a6ba4674..ce5423e5 100644
--- a/include/sys/io.h
+++ b/include/sys/io.h
@@ -4,8 +4,9 @@
extern "C" {
#endif
-int ioperm(unsigned long, unsigned long, int);
-int iopl(int);
+#include <features.h>
+
+#include <bits/io.h>
#ifdef __cplusplus
}
diff --git a/src/linux/ioperm.c b/src/linux/ioperm.c
index 6d7c37d0..08c6d8b8 100644
--- a/src/linux/ioperm.c
+++ b/src/linux/ioperm.c
@@ -1,7 +1,8 @@
-#include <sys/io.h>
#include "syscall.h"
#ifdef SYS_ioperm
+#include <sys/io.h>
+
int ioperm(unsigned long from, unsigned long num, int turn_on)
{
return syscall(SYS_ioperm, from, num, turn_on);
diff --git a/src/linux/iopl.c b/src/linux/iopl.c
index 5a626e16..835d3d4e 100644
--- a/src/linux/iopl.c
+++ b/src/linux/iopl.c
@@ -1,7 +1,8 @@
-#include <sys/io.h>
#include "syscall.h"
#ifdef SYS_iopl
+#include <sys/io.h>
+
int iopl(int level)
{
return syscall(SYS_iopl, level);