5 static inline unsigned char inb(const unsigned short port)
9 __asm__ __volatile__ ("inb %w1, %0" : "=a"(val) : "dN"(port));
14 static inline void outb(const unsigned short port, const unsigned char val)
16 int k = val; /* just here to test the b modifier in %b0 */
17 __asm__ __volatile__ ("outb %b0, %1" : : "a"(k), "dN"(port));
20 static void sincostest(double arg)
24 __asm__ ("fsincos" : "=t"(cos), "=u"(sin) : "0" (arg));
25 printf("Arg: %f Sin: %f Cos: %f\n", arg, sin, cos);
28 static inline int mov_noeax(int val)
32 __asm__ ("movl %1, %0" : "=r"(res) : "ri" (val) : "eax");
37 static inline unsigned short swap16(unsigned short x)
39 __asm__("xchgb %b0, %h0 /* in: %1 out: %0 */" : "=q" (x) : "0" (x));
43 static inline unsigned int swap32(unsigned int x)
45 __asm__("bswap %0 /* %1 */" : "=r" (x) : "0" (x));
51 __asm__("incl %0" : "+rm" (*v) : : "cc");
56 __asm__("incl %0" : "+m" (*v) : : "cc");
60 typedef struct kernel_fd_set {
65 typedef int kernel_fd_set;
68 void fd_set(int fd, kernel_fd_set* set) {
69 __asm__("btsl %1,%0" : "=m" (*(set)) : "r" (fd) : "cc");
72 int fd_isset(int fd, kernel_fd_set *set) {
75 __asm__ __volatile__("btl %1,%2\n"
78 : "r" (fd), "m" (*set)
87 return inb(20) + inb(5);
96 assert(fd_isset(20, &s));
98 printf("Swap16(0xAABB): %X Swap32(0xAABBCCDD): %X\n",
99 swap16(0xAABB), swap32(0xAABBCCDD));
102 printf("mov(inc(41)): %d\n", mov_noeax(k));
111 printf("Warning: asmtest only work on x86\n");