aboutsummaryrefslogtreecommitdiff
path: root/arch/x86_64/include
diff options
context:
space:
mode:
authorFelix Morgner <felix.morgner@ost.ch>2025-12-01 19:32:19 +0100
committerFelix Morgner <felix.morgner@ost.ch>2025-12-01 19:32:19 +0100
commit203355e51690073e571d4906d53f2494c3dad41b (patch)
tree538180b7d5fbaf4327394521c02d403537314c6b /arch/x86_64/include
parent005d7ea3df29e736750d409b816caa29cf9bab2f (diff)
downloadteachos-203355e51690073e571d4906d53f2494c3dad41b.tar.xz
teachos-203355e51690073e571d4906d53f2494c3dad41b.zip
x86_64/memory: prepare scoped_mapping extraction
Diffstat (limited to 'arch/x86_64/include')
-rw-r--r--arch/x86_64/include/x86_64/memory/scoped_mapping.hpp39
1 files changed, 39 insertions, 0 deletions
diff --git a/arch/x86_64/include/x86_64/memory/scoped_mapping.hpp b/arch/x86_64/include/x86_64/memory/scoped_mapping.hpp
new file mode 100644
index 0000000..1719e6b
--- /dev/null
+++ b/arch/x86_64/include/x86_64/memory/scoped_mapping.hpp
@@ -0,0 +1,39 @@
+#ifndef TEACHOS_X86_64_SCOPED_MAPPING_HPP
+#define TEACHOS_X86_64_SCOPED_MAPPING_HPP
+
+#include "kapi/memory.hpp"
+
+#include "x86_64/memory/page_table.hpp"
+
+namespace teachos::memory::x86_64
+{
+
+ struct scoped_mapping
+ {
+ scoped_mapping(scoped_mapping const &) = delete;
+ scoped_mapping(scoped_mapping &&);
+ scoped_mapping(linear_address address, frame_allocator & allocator);
+
+ ~scoped_mapping();
+
+ auto operator=(scoped_mapping const &) -> scoped_mapping = delete;
+ auto operator=(scoped_mapping &&) -> scoped_mapping &;
+
+ auto map(frame frame, page_table::entry::flags flags) -> std::byte *;
+ auto unmap() -> void;
+
+ template<typename DataType>
+ auto map_as(frame frame, page_table::entry::flags flags) -> DataType *
+ {
+ return std::bit_cast<DataType *>(map(frame, flags));
+ }
+
+ private:
+ linear_address m_address;
+ frame_allocator * m_allocator;
+ bool m_mapped;
+ };
+
+} // namespace teachos::memory::x86_64
+
+#endif \ No newline at end of file