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(int val)
32 __asm__ ("movl %1, %0" : "=r"(res) : "ri" (val));
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));
49 static inline void inc(int *v)
51 __asm__("incl %0" : "+g" (*v) : : "cc");
55 typedef struct kernel_fd_set {
60 typedef int kernel_fd_set;
63 void fd_set(int fd, kernel_fd_set* set) {
64 __asm__("btsl %1,%0" : "=m" (*(set)) : "r" (fd));
67 int fd_isset(int fd, kernel_fd_set *set) {
70 __asm__ __volatile__("btl %1,%2\n"
73 : "r" (fd), "m" (*set));
81 return inb(20) + inb(5);
90 assert(fd_isset(20, &s));
92 printf("Swap16(0xAABB): %X Swap32(0xAABBCCDD): %X\n",
93 swap16(0xAABB), swap32(0xAABBCCDD));
96 printf("mov(inc(41)): %d\n", mov(k));
105 printf("Warning: asmtest only work on x86\n");