da2798b05188ed97a14d425ba1da5247972f49e0
[lunaix-os.git] / lunaix-os / arch / i386 / includes / sys / port_io.h
1 #ifndef __LUNAIX_PORT_IO_H
2 #define __LUNAIX_PORT_IO_H
3
4 #include <lunaix/types.h>
5
6 static inline u8_t
7 port_rdbyte(int port)
8 {
9     u8_t data;
10     asm volatile("inb %w1,%0" : "=a"(data) : "d"(port));
11     return data;
12 }
13
14 static inline void
15 port_rdbytes(int port, void* addr, int cnt)
16 {
17     asm volatile("cld\n"
18                  "repne\n"
19                  "insb"
20                  : "=D"(addr), "=c"(cnt)
21                  : "d"(port), "0"(addr), "1"(cnt)
22                  : "memory", "cc");
23 }
24
25 static inline u16_t
26 port_rdword(int port)
27 {
28     u16_t data;
29     asm volatile("inw %w1,%0" : "=a"(data) : "d"(port));
30     return data;
31 }
32
33 static inline void
34 port_rdwords(int port, void* addr, int cnt)
35 {
36     asm volatile("cld\n"
37                  "repne\n"
38                  "insw"
39                  : "=D"(addr), "=c"(cnt)
40                  : "d"(port), "0"(addr), "1"(cnt)
41                  : "memory", "cc");
42 }
43
44 static inline u32_t
45 port_rddword(int port)
46 {
47     u32_t data;
48     asm volatile("inl %w1,%0" : "=a"(data) : "d"(port));
49     return data;
50 }
51
52 static inline void
53 port_rddwords(int port, void* addr, int cnt)
54 {
55     asm volatile("cld\n"
56                  "repne\n"
57                  "insl"
58                  : "=D"(addr), "=c"(cnt)
59                  : "d"(port), "0"(addr), "1"(cnt)
60                  : "memory", "cc");
61 }
62
63 static inline void
64 port_wrbyte(int port, u8_t data)
65 {
66     asm volatile("outb %0, %w1" : : "a"(data), "d"(port));
67 }
68
69 static inline void
70 port_wrbytes(int port, const void* addr, int cnt)
71 {
72     asm volatile("cld\n"
73                  "repne\n"
74                  "outsb"
75                  : "=S"(addr), "=c"(cnt)
76                  : "d"(port), "0"(addr), "1"(cnt)
77                  : "cc");
78 }
79
80 static inline void
81 port_wrword(int port, u16_t data)
82 {
83     asm volatile("outw %0,%w1" : : "a"(data), "d"(port));
84 }
85
86 static inline void
87 port_wrwords(int port, const void* addr, int cnt)
88 {
89     asm volatile("cld\n"
90                  "repne\n"
91                  "outsw"
92                  : "=S"(addr), "=c"(cnt)
93                  : "d"(port), "0"(addr), "1"(cnt)
94                  : "cc");
95 }
96
97 static inline void
98 port_wrdwords(int port, const void* addr, int cnt)
99 {
100     asm volatile("cld\n"
101                  "repne\n"
102                  "outsl"
103                  : "=S"(addr), "=c"(cnt)
104                  : "d"(port), "0"(addr), "1"(cnt)
105                  : "cc");
106 }
107
108 static inline void
109 port_wrdword(int port, u32_t data)
110 {
111     asm volatile("outl %0,%w1" : : "a"(data), "d"(port));
112 }
113
114 static inline void
115 port_delay(int counter)
116 {
117     asm volatile("   test %0, %0\n"
118                  "   jz 1f\n"
119                  "2: dec %0\n"
120                  "   jnz 2b\n"
121                  "1: dec %0" ::"a"(counter));
122 }
123
124 #endif /* __LUNAIX_PORT_port_H */