aboutsummaryrefslogtreecommitdiff
path: root/libs
diff options
context:
space:
mode:
authorFelix Morgner <felix.morgner@ost.ch>2025-07-23 13:21:32 +0000
committerFelix Morgner <felix.morgner@ost.ch>2025-07-23 13:21:32 +0000
commite97e86d169849527190cef1913efdd247e6f68df (patch)
treec46f0fe0eeaf50354f7a1c65304faae0b670a1b5 /libs
parent3a407e83b2dbd15936569ff90e4433078ea1cbaf (diff)
downloadteachos-e97e86d169849527190cef1913efdd247e6f68df.tar.xz
teachos-e97e86d169849527190cef1913efdd247e6f68df.zip
libs: move asm_ptr to kstd
Diffstat (limited to 'libs')
-rw-r--r--libs/kstd/CMakeLists.txt1
-rw-r--r--libs/kstd/include/kstd/asm_ptr55
2 files changed, 56 insertions, 0 deletions
diff --git a/libs/kstd/CMakeLists.txt b/libs/kstd/CMakeLists.txt
index b0abaaf..ac9e78f 100644
--- a/libs/kstd/CMakeLists.txt
+++ b/libs/kstd/CMakeLists.txt
@@ -13,6 +13,7 @@ target_sources("kstd" PUBLIC
"include/kstd/bits/shared_ptr.hpp"
"include/kstd/bits/unique_ptr.hpp"
+ "include/kstd/asm_ptr"
"include/kstd/memory"
"include/kstd/mutex"
"include/kstd/stack"
diff --git a/libs/kstd/include/kstd/asm_ptr b/libs/kstd/include/kstd/asm_ptr
new file mode 100644
index 0000000..e9072e2
--- /dev/null
+++ b/libs/kstd/include/kstd/asm_ptr
@@ -0,0 +1,55 @@
+#ifndef KSTD_ASM_POINTER_HPP
+#define KSTD_ASM_POINTER_HPP
+
+#include <bit>
+
+namespace kstd
+{
+
+ /**
+ * @brief A pointer that is defined in some assembly source file.
+ *
+ * @tparam Type The type of the pointer
+ */
+ template<typename Type>
+ struct asm_ptr
+ {
+ using value_type = Type;
+ using pointer = value_type *;
+ using const_pointer = value_type const *;
+ using reference = value_type &;
+ using const_reference = value_type const &;
+
+ asm_ptr() = delete;
+ asm_ptr(asm_ptr const &) = delete;
+ asm_ptr(asm_ptr &&) = delete;
+
+ auto constexpr operator=(asm_ptr const &) = delete;
+ auto constexpr operator=(asm_ptr &&) = delete;
+
+ auto get() const noexcept -> pointer { return m_ptr; }
+
+ auto constexpr operator+(std::ptrdiff_t offset) const noexcept -> pointer
+ {
+ return std::bit_cast<pointer>(m_ptr) + offset;
+ }
+
+ auto constexpr operator*() noexcept -> reference { return *(std::bit_cast<pointer>(m_ptr)); }
+
+ auto constexpr operator*() const noexcept -> const_reference { return *(std::bit_cast<const_pointer>(m_ptr)); }
+
+ auto constexpr operator[](std::ptrdiff_t offset) noexcept -> reference { return *(*this + offset); }
+
+ auto constexpr operator[](std::ptrdiff_t offset) const noexcept -> const_reference { return *(*this + offset); }
+
+ auto constexpr operator->() noexcept -> pointer { return m_ptr; }
+
+ auto constexpr operator->() const noexcept -> const_pointer { return m_ptr; }
+
+ private:
+ pointer m_ptr;
+ };
+
+} // namespace kstd
+
+#endif \ No newline at end of file