summaryrefslogtreecommitdiff
path: root/mmio
diff options
context:
space:
mode:
authorVegard Storheil Eriksen <zyp@jvnv.net>2021-01-21 21:48:58 +0100
committerVegard Storheil Eriksen <zyp@jvnv.net>2021-01-21 21:48:58 +0100
commit13bb78203cac7d3a582da55e004c84104ff214dd (patch)
tree9e8adf467003e9fe876713dca1cb2a1dbf76b641 /mmio
parent172d694cf7ba582635ac38454bad0f0fdaa14773 (diff)
mmio: Add mmio_ptr template.
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];
+ }
+};