#include <stdio.h>
+#include <assert.h>
+#ifdef __i386__
static inline unsigned char inb(const unsigned short port)
{
unsigned char val;
{
int res;
- __asm__ ("movl %0, %1" : "=r"(res) : "ri" (val));
+ __asm__ ("movl %1, %0" : "=r"(res) : "ri" (val));
return res;
}
+static inline unsigned short swap16(unsigned short x)
+{
+ __asm__("xchgb %b0, %h0 /* in: %1 out: %0 */" : "=q" (x) : "0" (x));
+ return x;
+}
-int main()
+static inline unsigned int swap32(unsigned int x)
+{
+ __asm__("bswap %0 /* %1 */" : "=r" (x) : "0" (x));
+ return x;
+}
+
+#if 1
+typedef struct kernel_fd_set {
+ int bla;
+ int blup;
+} kernel_fd_set;
+#else
+typedef int kernel_fd_set;
+#endif
+
+void fd_set(int fd, kernel_fd_set* set) {
+ __asm__("btsl %1,%0" : "=m" (*(set)) : "r" (fd));
+}
+
+int fd_isset(int fd, kernel_fd_set *set) {
+ unsigned char result;
+
+ __asm__ __volatile__("btl %1,%2\n"
+ "\tsetb %0"
+ : "=q" (result)
+ : "r" (fd), "m" (*set));
+ return result;
+}
+
+int justcompile(void)
{
- //sincostest(0.5);
outb(123, 42);
outb(12345, 42);
+ return inb(20) + inb(5);
+}
+
+int main()
+{
+ kernel_fd_set s;
+
+ fd_set(20, &s);
+ assert(fd_isset(20, &s));
+
+ printf("Swap16: %d Swap32: %d\n", swap16(12), swap32(123551235));
- return mov(0) + inb(12345) + inb(123);
+ return mov(0);
}
+
+#else
+
+int main()
+{
+ printf("Warning: asmtest only work on x86\n");
+ return 0;
+}
+
+#endif