blob: 9759a3a950a8c8829519fab678ab6dbb0f462107 (
plain)
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
|
#pragma once
/**
* Ports provide communication with devices on the x86 IO bus.
*/
template <typename T, unsigned short port> struct Port {
/**
* Read value from port
*/
static T
in(unsigned short offset = 0)
{
if constexpr (sizeof(T) == sizeof(unsigned char)) return inb(port + offset);
else if constexpr (sizeof(T) == sizeof(unsigned short))
return inw(port + offset);
else if constexpr (sizeof(T) == sizeof(unsigned int))
return inl(port + offset);
}
/**
* Write value to port
*/
static void
out(T val, unsigned short offset = 0)
{
if constexpr (sizeof(T) == sizeof(unsigned char)) outb(val, port + offset);
else if constexpr (sizeof(T) == sizeof(unsigned short))
outw(val, port + offset);
else if constexpr (sizeof(T) == sizeof(unsigned int))
outl(val, port + offset);
}
};
|