diff options
| author | Felix Morgner <felix.morgner@ost.ch> | 2025-07-14 16:42:26 +0000 |
|---|---|---|
| committer | Felix Morgner <felix.morgner@ost.ch> | 2025-07-14 16:42:26 +0000 |
| commit | d1aaaeb615e148a13f46223c84819ba828e5209f (patch) | |
| tree | 9a1fb3d5ff429f4bf96f999dbc6751ec1cc6b976 /kern/include | |
| parent | ec572bff8150e2f8cd2dc99e053c5e8c8a0b99e3 (diff) | |
| download | teachos-d1aaaeb615e148a13f46223c84819ba828e5209f.tar.xz teachos-d1aaaeb615e148a13f46223c84819ba828e5209f.zip | |
arch: make linkable
Diffstat (limited to 'kern/include')
| -rw-r--r-- | kern/include/kern/asm_pointer.hpp | 76 |
1 files changed, 76 insertions, 0 deletions
diff --git a/kern/include/kern/asm_pointer.hpp b/kern/include/kern/asm_pointer.hpp new file mode 100644 index 0000000..4c25658 --- /dev/null +++ b/kern/include/kern/asm_pointer.hpp @@ -0,0 +1,76 @@ +#ifndef TEACHOS_MEMORY_ASM_POINTER_HPP +#define TEACHOS_MEMORY_ASM_POINTER_HPP + +namespace teachos::memory +{ + + /** + * @brief A pointer that is defined in some assembly source file. + * + * @tparam Type The type of the pointer + * @since 0.0.1 + */ + template<typename Type> + struct asm_pointer + { + /** + * @brief The type of the underlying pointer. + */ + using pointer = Type *; + + /** + * @brief Construct a new asm_pointer for a given assembly-defined pointer. + * + * @param pointer A pointer defined in assembly. + */ + constexpr asm_pointer(Type *& pointer) + : m_pointer{&pointer} + { + // Nothing to do + } + + /** + * @brief Access the underlying pointer. + * + * @return The pointer wrapped by this asm_pointer. + */ + auto constexpr operator*() -> pointer & { return *m_pointer; } + + /** + * @brief Access the underlying pointer. + * + * @return The pointer wrapped by this asm_pointer. + */ + auto constexpr operator*() const -> pointer const & { return *m_pointer; } + + private: + pointer * m_pointer; + }; + + /** + * @copydoc asm_pointer + * + * @note This specialization allows the use of this type for pointers to constant data. + * @since 0.0.1 + */ + template<typename Type> + struct asm_pointer<Type const> + { + /** @copydoc asm_pointer<Type>::asm_pointer */ + constexpr asm_pointer(Type const & pointer) + : m_pointer{&pointer} + { + } + + /** @copydoc asm_pointer<Type>::operator*() */ + auto constexpr operator*() -> Type const & { return *m_pointer; } + /** @copydoc asm_pointer<Type>::operator*() const */ + auto constexpr operator*() const -> Type const & { return *m_pointer; } + + private: + Type const * m_pointer; + }; + +} // namespace teachos::memory + +#endif // TEACHOS_MEMORY_ASM_POINTER_HPP |
