aboutsummaryrefslogtreecommitdiff
path: root/i686
diff options
context:
space:
mode:
authoraqua <aqua@iserlohn-fortress.net>2022-12-11 21:42:29 +0200
committeraqua <aqua@iserlohn-fortress.net>2022-12-11 21:42:29 +0200
commitf398efa1ac52e967d9673a0efebd9a27f17d60bf (patch)
treeddf0460a1cf6f1ab8fd71de250e581f7f4e51b37 /i686
parentMove symlink target to leaf makefiles (diff)
downloadkernel-f398efa1ac52e967d9673a0efebd9a27f17d60bf.tar.xz
Generate docs using doxygen instead of sphinx
Diffstat (limited to 'i686')
-rw-r--r--i686/sys/io.hpp30
1 files changed, 24 insertions, 6 deletions
diff --git a/i686/sys/io.hpp b/i686/sys/io.hpp
index bea9323..9759a3a 100644
--- a/i686/sys/io.hpp
+++ b/i686/sys/io.hpp
@@ -1,15 +1,33 @@
#pragma once
+/**
+ * Ports provide communication with devices on the x86 IO bus.
+ */
template <typename T, unsigned short port> struct Port {
- static void
- out(T val, unsigned short offset = 0)
+ /**
+ * Read value from port
+ */
+ static T
+ in(unsigned short offset = 0)
{
- outb(val, port + offset);
+ 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);
}
- static auto
- in(unsigned short offset = 0)
+ /**
+ * Write value to port
+ */
+ static void
+ out(T val, unsigned short offset = 0)
{
- return inb(port + offset);
+ 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);
}
+
};