- Initial checkin of the freebios2 tree
[coreboot.git] / src / arch / i386 / include / arch / io.h
1 #ifndef _ASM_IO_H
2 #define _ASM_IO_H
3
4 /*
5  * This file contains the definitions for the x86 IO instructions
6  * inb/inw/inl/outb/outw/outl and the "string versions" of the same
7  * (insb/insw/insl/outsb/outsw/outsl).
8  *
9  * This file is not meant to be obfuscating: it's just complicated
10  * to (a) handle it all in a way that makes gcc able to optimize it
11  * as well as possible and (b) trying to avoid writing the same thing
12  * over and over again with slight variations and possibly making a
13  * mistake somewhere.
14  */
15
16  /*
17   *  Bit simplified and optimized by Jan Hubicka
18   *  Support of BIGMEM added by Gerhard Wichert, Siemens AG, July 1999.
19   */
20
21 /*
22  * Talk about misusing macros..
23  */
24 #define __OUT1(s,x) \
25 extern inline void out##s(unsigned x value, unsigned short port) {
26
27 #define __OUT2(s,s1,s2) \
28 __asm__ __volatile__ ("out" #s " %" s1 "0,%" s2 "1"
29
30 #define __OUT(s,s1,x) \
31 __OUT1(s,x) __OUT2(s,s1,"w") : : "a" (value), "Nd" (port)); } 
32
33 #define __IN1(s) \
34 extern inline RETURN_TYPE in##s(unsigned short port) { RETURN_TYPE _v;
35
36 #define __IN2(s,s1,s2) \
37 __asm__ __volatile__ ("in" #s " %" s2 "1,%" s1 "0"
38
39 #define __IN(s,s1,i...) \
40 __IN1(s) __IN2(s,s1,"w") : "=a" (_v) : "Nd" (port) ,##i ); return _v; } 
41
42 #define __INS(s) \
43 extern inline void ins##s(unsigned short port, void * addr, unsigned long count) \
44 { __asm__ __volatile__ ("cld ; rep ; ins" #s \
45 : "=D" (addr), "=c" (count) : "d" (port),"0" (addr),"1" (count)); }
46
47 #define __OUTS(s) \
48 extern inline void outs##s(unsigned short port, const void * addr, unsigned long count) \
49 { __asm__ __volatile__ ("cld ; rep ; outs" #s \
50 : "=S" (addr), "=c" (count) : "d" (port),"0" (addr),"1" (count)); }
51
52 #define RETURN_TYPE unsigned char
53 __IN(b,"")
54 #undef RETURN_TYPE
55 #define RETURN_TYPE unsigned short
56 __IN(w,"")
57 #undef RETURN_TYPE
58 #define RETURN_TYPE unsigned int
59 __IN(l,"")
60 #undef RETURN_TYPE
61
62 __OUT(b,"b",char)
63 __OUT(w,"w",short)
64 __OUT(l,,int)
65
66 __INS(b)
67 __INS(w)
68 __INS(l)
69
70 __OUTS(b)
71 __OUTS(w)
72 __OUTS(l)
73
74
75 #endif
76