summaryrefslogtreecommitdiff
path: root/mmio
diff options
context:
space:
mode:
Diffstat (limited to 'mmio')
-rw-r--r--mmio/mmio.h29
1 files changed, 29 insertions, 0 deletions
diff --git a/mmio/mmio.h b/mmio/mmio.h
new file mode 100644
index 0000000..a756c8f
--- /dev/null
+++ b/mmio/mmio.h
@@ -0,0 +1,29 @@
+#pragma once
+
+#include <cstdint>
+
+template <typename T>
+class mmio_ptr {
+ private:
+ const uintptr_t p;
+
+ protected:
+ T* ptr() const {
+ return reinterpret_cast<T*>(p);
+ }
+
+ public:
+ constexpr mmio_ptr(uintptr_t p) : p(p) {}
+
+ T* operator->() const {
+ return ptr();
+ }
+
+ T& operator*() const {
+ return *ptr();
+ }
+
+ T& operator[](std::size_t idx) const {
+ return ptr()[idx];
+ }
+};