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