* added 0.99 linux version
[mascara-docs.git] / i386 / linux / linux-0.99 / include / asm / io.h
bloba2527c1e0b4b334ae9ceac9bbb022b50e1d99832
1 #ifndef _ASM_IO_H
2 #define _ASM_IO_H
4 /*
5 * Thanks to James van Artsdalen for a better timing-fix than
6 * the two short jumps: using outb's to a nonexistent port seems
7 * to guarantee better timings even on fast machines.
9 * On the other hand, I'd like to be sure of a non-existent port:
10 * I feel a bit unsafe about using 0x80 (should be safe, though)
12 * Linus
15 #ifdef SLOW_IO_BY_JUMPING
16 #define __SLOW_DOWN_IO __asm__ __volatile__("jmp 1f\n1:\tjmp 1f\n1:")
17 #else
18 #define __SLOW_DOWN_IO __asm__ __volatile__("outb %al,$0x80")
19 #endif
21 #ifdef REALLY_SLOW_IO
22 #define SLOW_DOWN_IO { __SLOW_DOWN_IO; __SLOW_DOWN_IO; __SLOW_DOWN_IO; __SLOW_DOWN_IO; }
23 #else
24 #define SLOW_DOWN_IO __SLOW_DOWN_IO
25 #endif
28 * Talk about misusing macros..
31 #define __OUT1(s,x) \
32 extern inline void __out##s(unsigned x value, unsigned short port) {
34 #define __OUT2(s,s1,s2) \
35 __asm__ __volatile__ ("out" #s " %" s1 "0,%" s2 "1"
37 #define __OUT(s,s1,x) \
38 __OUT1(s,x) __OUT2(s,s1,"w") : : "a" (value), "d" (port)); } \
39 __OUT1(s##c,x) __OUT2(s,s1,"") : : "a" (value), "i" (port)); } \
40 __OUT1(s##_p,x) __OUT2(s,s1,"w") : : "a" (value), "d" (port)); SLOW_DOWN_IO; } \
41 __OUT1(s##c_p,x) __OUT2(s,s1,"") : : "a" (value), "i" (port)); SLOW_DOWN_IO; }
43 #define __IN1(s) \
44 extern inline unsigned int __in##s(unsigned short port) { unsigned int _v;
46 #define __IN2(s,s1,s2) \
47 __asm__ __volatile__ ("in" #s " %" s2 "1,%" s1 "0"
49 #define __IN(s,s1,i...) \
50 __IN1(s) __IN2(s,s1,"w") : "=a" (_v) : "d" (port) ,##i ); return _v; } \
51 __IN1(s##c) __IN2(s,s1,"") : "=a" (_v) : "i" (port) ,##i ); return _v; } \
52 __IN1(s##_p) __IN2(s,s1,"w") : "=a" (_v) : "d" (port) ,##i ); SLOW_DOWN_IO; return _v; } \
53 __IN1(s##c_p) __IN2(s,s1,"") : "=a" (_v) : "i" (port) ,##i ); SLOW_DOWN_IO; return _v; }
55 #define __INS(s) \
56 extern inline void ins##s(unsigned short port, void * addr, unsigned long count) \
57 { __asm__ __volatile__ ("cld ; rep ; ins" #s \
58 : "=D" (addr), "=c" (count) : "d" (port),"0" (addr),"1" (count)); }
60 #define __OUTS(s) \
61 extern inline void outs##s(unsigned short port, const void * addr, unsigned long count) \
62 { __asm__ __volatile__ ("cld ; rep ; outs" #s \
63 : "=S" (addr), "=c" (count) : "d" (port),"0" (addr),"1" (count)); }
65 __IN(b,"b","0" (0))
66 __IN(w,"w","0" (0))
67 __IN(l,"")
69 __OUT(b,"b",char)
70 __OUT(w,"w",short)
71 __OUT(l,,int)
73 __INS(b)
74 __INS(w)
75 __INS(l)
77 __OUTS(b)
78 __OUTS(w)
79 __OUTS(l)
82 * Note that due to the way __builtin_constant_p() works, you
83 * - can't use it inside a inline function (it will never be true)
84 * - you don't have to worry about side effects within the __builtin..
86 #define outb(val,port) \
87 ((__builtin_constant_p((port)) && (port) < 256) ? \
88 __outbc((val),(port)) : \
89 __outb((val),(port)))
91 #define inb(port) \
92 ((__builtin_constant_p((port)) && (port) < 256) ? \
93 __inbc(port) : \
94 __inb(port))
96 #define outb_p(val,port) \
97 ((__builtin_constant_p((port)) && (port) < 256) ? \
98 __outbc_p((val),(port)) : \
99 __outb_p((val),(port)))
101 #define inb_p(port) \
102 ((__builtin_constant_p((port)) && (port) < 256) ? \
103 __inbc_p(port) : \
104 __inb_p(port))
106 #define outw(val,port) \
107 ((__builtin_constant_p((port)) && (port) < 256) ? \
108 __outwc((val),(port)) : \
109 __outw((val),(port)))
111 #define inw(port) \
112 ((__builtin_constant_p((port)) && (port) < 256) ? \
113 __inwc(port) : \
114 __inw(port))
116 #define outw_p(val,port) \
117 ((__builtin_constant_p((port)) && (port) < 256) ? \
118 __outwc_p((val),(port)) : \
119 __outw_p((val),(port)))
121 #define inw_p(port) \
122 ((__builtin_constant_p((port)) && (port) < 256) ? \
123 __inwc_p(port) : \
124 __inw_p(port))
126 #define outl(val,port) \
127 ((__builtin_constant_p((port)) && (port) < 256) ? \
128 __outlc((val),(port)) : \
129 __outl((val),(port)))
131 #define inl(port) \
132 ((__builtin_constant_p((port)) && (port) < 256) ? \
133 __inlc(port) : \
134 __inl(port))
136 #define outl_p(val,port) \
137 ((__builtin_constant_p((port)) && (port) < 256) ? \
138 __outlc_p((val),(port)) : \
139 __outl_p((val),(port)))
141 #define inl_p(port) \
142 ((__builtin_constant_p((port)) && (port) < 256) ? \
143 __inlc_p(port) : \
144 __inl_p(port))
146 #endif