-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathport.cpp
51 lines (41 loc) · 1.1 KB
/
port.cpp
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
#include "port.h"
template<typename T>
Port<T>::Port(uint16_t port) : port(port) {};
template<typename T>
Port<T>::~Port(){};
template<>
void Port<uint8_t>::write(uint8_t data) {
__asm__ volatile("outb %0, %1" : : "a"(data), "Nd"(port));
}
template<>
void Port<uint16_t>::write(uint16_t data) {
__asm__ volatile("outw %0, %1" : : "a"(data), "Nd"(port));
}
template<>
void Port<uint32_t>::write(uint32_t data) {
__asm__ volatile("outl %0, %1" : : "a"(data), "Nd"(port));
}
template<>
uint8_t Port<uint8_t>::read() {
uint8_t result;
__asm__ volatile("inb %1, %0" : "=a"(result) : "Nd"(port));
return result;
}
template<>
uint16_t Port<uint16_t>::read() {
uint16_t result;
__asm__ volatile("inw %1, %0" : "=a"(result) : "Nd"(port));
return result;
}
template<>
uint32_t Port<uint32_t>::read() {
uint32_t result;
__asm__ volatile("inl %1, %0" : "=a"(result) : "Nd"(port));
return result;
}
Port8slow::Port8slow(uint16_t port) : Port8(port) {};
Port8slow::~Port8slow() {
}
void Port8slow::write(uint8_t data) {
__asm__ volatile("outb %0, %1\njmp 1f\n1: jmp 1f\n1:" : : "a"(data), "Nd"(port));
}