Max OS 0.3
Loading...
Searching...
No Matches
port.cpp
Go to the documentation of this file.
1
10
11using namespace MaxOS::hardwarecommunication;
12
18Port::Port(uint16_t port_number)
19: m_port_number(port_number)
20{
21}
22
23Port::~Port() = default;
24
30Port8Bit::Port8Bit(uint16_t port_number)
31: Port(port_number) {
32}
33
34Port8Bit::~Port8Bit() = default;
35
41void Port8Bit::write(uint8_t data) {
42
43 asm volatile("outb %0, %1" : : "a" (data), "Nd" (m_port_number));
44}
45
51uint8_t Port8Bit::read() {
52
53 uint8_t result;
54 asm volatile("inb %1, %0" : "=a" (result) : "Nd" (m_port_number));
55 return result;
56}
57
63Port8BitSlow::Port8BitSlow(uint16_t port_number)
64: Port8Bit(port_number) {
65}
66
67Port8BitSlow::~Port8BitSlow() = default;
68
74void Port8BitSlow::write(uint8_t data) {
75
76 asm volatile("outb %0, %1\njmp 1f\n1: jmp 1f\n1:" : : "a" (data), "Nd" (m_port_number));
77}
78
84Port16Bit::Port16Bit(uint16_t port_number)
85: Port(port_number) {
86}
87
88Port16Bit::~Port16Bit() = default;
89
95void Port16Bit::write(uint16_t data) {
96
97 asm volatile("outw %0, %1" : : "a" (data), "Nd" (m_port_number));
98}
99
105uint16_t Port16Bit::read() {
106
107 uint16_t result;
108 asm volatile("inw %1, %0" : "=a" (result) : "Nd" (m_port_number));
109 return result;
110}
111
117Port32Bit::Port32Bit(uint16_t port_number)
118: Port(port_number) {
119}
120
121Port32Bit::~Port32Bit() = default;
122
128void Port32Bit::write(uint32_t data) {
129
130 asm volatile("outl %0, %1" : : "a" (data), "Nd" (m_port_number));
131}
132
138uint32_t Port32Bit::read() {
139
140 uint32_t result;
141 asm volatile("inl %1, %0" : "=a" (result) : "Nd" (m_port_number));
142 return result;
143}
virtual void write(uint16_t data)
write a word to the port
Definition port.cpp:95
virtual uint16_t read()
read a word from the port
Definition port.cpp:105
Port16Bit(uint16_t port_number)
Construct a new Port object for ports handling 16 bit read/writes.
Definition port.cpp:84
virtual uint32_t read()
read a double word from the port (32Bit)
Definition port.cpp:138
Port32Bit(uint16_t port_number)
Construct a new Port object for ports handling 32 bit read/writes.
Definition port.cpp:117
virtual void write(uint32_t data)
write a double word to the port (32Bit)
Definition port.cpp:128
void write(uint8_t data) final
write a byte to the port (slow)
Definition port.cpp:74
Port8BitSlow(uint16_t port_number)
Construct a new Port object for ports handling 8 bit read/writes (slow)
Definition port.cpp:63
virtual uint8_t read()
read a byte from the port
Definition port.cpp:51
Port8Bit(uint16_t port_number)
Construct a new Port object for ports handling 8 bit read/writes.
Definition port.cpp:30
virtual void write(uint8_t data)
write a byte to the port
Definition port.cpp:41
base class for all ports
Definition port.h:20
Port(uint16_t port_number)
Construct a new Port object.
Definition port.cpp:18
uint16_t m_port_number
The port to write to / read from.
Definition port.h:22
Defines classes for handling hardware communication ports (8, 16, and 32 bit)