-
Notifications
You must be signed in to change notification settings - Fork 0
/
port.h
111 lines (81 loc) · 2.61 KB
/
port.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
#ifndef __PORT_H
#define __PORT_H
#include "types.h"
class Port
{
protected:
Port(uint16_t portnumber);
// FIXME: Must be virtual (currently isnt because the kernel has no memory management yet)
~Port();
uint16_t portnumber;
};
class Port8Bit : public Port
{
public:
Port8Bit(uint16_t portnumber);
~Port8Bit();
virtual uint8_t Read();
virtual void Write(uint8_t data);
protected:
static inline uint8_t Read8(uint16_t _port)
{
uint8_t result;
__asm__ volatile("inb %1, %0" : "=a" (result) : "Nd" (_port));
return result;
}
static inline void Write8(uint16_t _port, uint8_t _data)
{
__asm__ volatile("outb %0, %1" : : "a" (_data), "Nd" (_port));
}
};
class Port8BitSlow : public Port8Bit
{
public:
Port8BitSlow(uint16_t portnumber);
~Port8BitSlow();
virtual void Write(uint8_t data);
protected:
static inline void Write8Slow(uint16_t _port, uint8_t _data)
{
__asm__ volatile("outb %0, %1\njmp 1f\n1: jmp 1f\n1:" : : "a" (_data), "Nd" (_port));
}
};
class Port16Bit : public Port
{
public:
Port16Bit(uint16_t portnumber);
~Port16Bit();
virtual uint16_t Read();
virtual void Write(uint16_t data);
protected:
static inline uint16_t Read16(uint16_t _port)
{
uint16_t result;
__asm__ volatile("inw %1, %0" : "=a" (result) : "Nd" (_port));
return result;
}
static inline void Write16(uint16_t _port, uint16_t _data)
{
__asm__ volatile("outw %0, %1" : : "a" (_data), "Nd" (_port));
}
};
class Port32Bit : public Port
{
public:
Port32Bit(uint16_t portnumber);
~Port32Bit();
virtual uint32_t Read();
virtual void Write(uint32_t data);
protected:
static inline uint32_t Read32(uint16_t _port)
{
uint32_t result;
__asm__ volatile("inl %1, %0" : "=a" (result) : "Nd" (_port));
return result;
}
static inline void Write32(uint16_t _port, uint32_t _data)
{
__asm__ volatile("outl %0, %1" : : "a"(_data), "Nd" (_port));
}
};
#endif