Add comments.
[pintos-anon] / src / threads / io.h
1 #ifndef HEADER_IO_H
2 #define HEADER_IO_H 1
3
4 #include <stddef.h>
5 #include <stdint.h>
6
7 /* Reads and returns a byte from PORT. */
8 static inline uint8_t
9 inb (uint16_t port)
10 {
11   uint8_t data;
12   asm volatile ("inb %w1,%0" : "=a" (data) : "d" (port));
13   return data;
14 }
15
16 /* Reads CNT bytes from PORT, one after another, and stores them
17    into the buffer starting at ADDR. */
18 static inline void
19 insb (uint16_t port, void *addr, size_t cnt)
20 {
21   asm volatile ("cld; repne; insb"
22                 : "=D" (addr), "=c" (cnt)
23                 : "d" (port), "0" (addr), "1" (cnt)
24                 : "memory", "cc");
25 }
26
27 /* Reads and returns 16 bits from PORT. */
28 static inline uint16_t
29 inw (uint16_t port)
30 {
31   uint16_t data;
32   asm volatile ("inw %w1,%0" : "=a" (data) : "d" (port));
33   return data;
34 }
35
36 /* Reads CNT 16-bit (halfword) units from PORT, one after
37    another, and stores them into the buffer starting at ADDR. */
38 static inline void
39 insw (uint16_t port, void *addr, size_t cnt)
40 {
41   asm volatile ("cld; repne; insw"
42                 : "=D" (addr), "=c" (cnt)
43                 : "d" (port), "0" (addr), "1" (cnt)
44                 : "memory", "cc");
45 }
46
47 /* Reads and returns 32 bits from PORT. */
48 static inline uint32_t
49 inl (uint16_t port)
50 {
51   uint32_t data;
52   asm volatile ("inl %w1,%0" : "=a" (data) : "d" (port));
53   return data;
54 }
55
56 /* Reads CNT 32-bit (word) units from PORT, one after another,
57    and stores them into the buffer starting at ADDR. */
58 static inline void
59 insl (uint16_t port, void *addr, size_t cnt)
60 {
61   asm volatile ("cld; repne; insl"
62                 : "=D" (addr), "=c" (cnt)
63                 : "d" (port), "0" (addr), "1" (cnt)
64                 : "memory", "cc");
65 }
66
67 /* Writes byte DATA to PORT. */
68 static inline void
69 outb (uint16_t port, uint8_t data)
70 {
71   asm volatile ("outb %0,%w1" : : "a" (data), "d" (port));
72 }
73
74 /* Writes to PORT each byte of data in the CNT-byte buffer
75    starting at ADDR. */
76 static inline void
77 outsb (uint16_t port, const void *addr, size_t cnt)
78 {
79   asm volatile ("cld; repne; outsb"
80                 : "=S" (addr), "=c" (cnt)
81                 : "d" (port), "0" (addr), "1" (cnt)
82                 : "cc");
83 }
84
85 /* Writes the 16-bit DATA to PORT. */
86 static inline void
87 outw (uint16_t port, uint16_t data)
88 {
89   asm volatile ("outw %0,%w1" : : "a" (data), "d" (port));
90 }
91
92 /* Writes to PORT each 16-bit unit (halfword) of data in the
93    CNT-halfword buffer starting at ADDR. */
94 static inline void
95 outsw (uint16_t port, const void *addr, size_t cnt)
96 {
97   asm volatile ("cld; repne; outsw"
98                 : "=S" (addr), "=c" (cnt)
99                 : "d" (port), "0" (addr), "1" (cnt)
100                 : "cc");
101 }
102
103 /* Writes the 32-bit DATA to PORT. */
104 static inline void
105 outl (uint16_t port, uint32_t data)
106 {
107   asm volatile ("outl %0,%w1" : : "a" (data), "d" (port));
108 }
109
110 /* Writes to PORT each 32-bit unit (word) of data in the CNT-word
111    buffer starting at ADDR. */
112 static inline void
113 outsl (uint16_t port, const void *addr, size_t cnt)
114 {
115   asm volatile ("cld; repne; outsl"
116                 : "=S" (addr), "=c" (cnt)
117                 : "d" (port), "0" (addr), "1" (cnt)
118                 : "cc");
119 }
120
121 #endif /* io.h */