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
|
#pragma once
// port listings
enum UART {
COM1 = 0x3f8,
COM2 = 0x2f8,
COM3 = 0x3e8,
COM4 = 0x2e8,
COM5 = 0x5f8,
COM6 = 0x4f8,
COM7 = 0x5e8,
COM8 = 0x4e8,
};
enum UARTPortOffset {
Data = 0, // read from receive buffer / write to transmit buffer | BaudDiv_l
InterruptControl = 1, // interrupt enable | BaudDiv_h
FifoControl = 2, // interrupt ID and FIFO control
LineControl = 3, // most significant bit is the DLAB
ModemControl = 4,
LineStatus = 5,
ModemStatus = 6,
Scratch = 7,
};
static inline void
outb(unsigned char val, unsigned short port)
{
asm volatile("outb %0,%1" : : "a"(val), "dN"(port));
}
static inline void
outw(unsigned short val, unsigned short port)
{
asm volatile("outw %0,%1" : : "a"(val), "dN"(port));
}
static inline void
outl(unsigned int val, unsigned short port)
{
asm volatile("outl %0,%1" : : "a"(val), "dN"(port));
}
static inline unsigned char
inb(unsigned short port)
{
unsigned char val;
asm volatile("inb %1,%0" : "=a"(val) : "dN"(port));
return val;
}
static inline unsigned short
inw(unsigned short port)
{
unsigned short val;
asm volatile("inw %1,%0" : "=a"(val) : "dN"(port));
return val;
}
static inline unsigned int
inl(unsigned short port)
{
unsigned int val;
asm volatile("inl %1,%0" : "=a"(val) : "dN"(port));
return val;
}
static inline void
outsb(unsigned short port, const void *__buf, unsigned long __n)
{
asm volatile("cld; rep; outsb" : "+S"(__buf), "+c"(__n) : "d"(port));
}
static inline void
outsw(unsigned short port, const void *__buf, unsigned long __n)
{
asm volatile("cld; rep; outsw" : "+S"(__buf), "+c"(__n) : "d"(port));
}
static inline void
outsl(unsigned short port, const void *__buf, unsigned long __n)
{
asm volatile("cld; rep; outsl" : "+S"(__buf), "+c"(__n) : "d"(port));
}
static inline void
insb(unsigned short port, void *__buf, unsigned long __n)
{
asm volatile("cld; rep; insb" : "+D"(__buf), "+c"(__n) : "d"(port));
}
static inline void
insw(unsigned short port, void *__buf, unsigned long __n)
{
asm volatile("cld; rep; insw" : "+D"(__buf), "+c"(__n) : "d"(port));
}
static inline void
insl(unsigned short port, void *__buf, unsigned long __n)
{
asm volatile("cld; rep; insl" : "+D"(__buf), "+c"(__n) : "d"(port));
}
|