aboutsummaryrefslogtreecommitdiff
path: root/kapi
diff options
context:
space:
mode:
authorFelix Morgner <felix.morgner@ost.ch>2026-03-16 08:34:13 +0100
committerFelix Morgner <felix.morgner@ost.ch>2026-03-16 08:34:13 +0100
commit64bf7fcf58ced023be1701ed4508e38f746d40b8 (patch)
tree023637c060d169e5a72576f62c9bd616b8b5b937 /kapi
parent1e23bfc850f0ca126bff3c56c86419ab1570c96e (diff)
downloadteachos-64bf7fcf58ced023be1701ed4508e38f746d40b8.tar.xz
teachos-64bf7fcf58ced023be1701ed4508e38f746d40b8.zip
kernel/memory: implement basic free-list heap
Diffstat (limited to 'kapi')
-rw-r--r--kapi/include/kapi/memory.hpp3
-rw-r--r--kapi/include/kapi/memory/address.hpp19
-rw-r--r--kapi/include/kapi/memory/page.hpp8
-rw-r--r--kapi/include/kapi/memory/page_mapper.hpp3
4 files changed, 24 insertions, 9 deletions
diff --git a/kapi/include/kapi/memory.hpp b/kapi/include/kapi/memory.hpp
index b234cde..9ef2cd7 100644
--- a/kapi/include/kapi/memory.hpp
+++ b/kapi/include/kapi/memory.hpp
@@ -78,8 +78,9 @@ namespace kapi::memory
//!
//! @param page The page to map.
//! @param frame The frame to map the page into.
+ //! @param flags The flags to apply to this mapping.
//! @return A pointer to the first byte of the mapped page.
- auto map(page page, frame frame) -> std::byte *;
+ auto map(page page, frame frame, page_mapper::flags flags = page_mapper::flags::empty) -> std::byte *;
//! @qualifier kernel-defined
//! Unmap a page.
diff --git a/kapi/include/kapi/memory/address.hpp b/kapi/include/kapi/memory/address.hpp
index 39eb1ee..e5cf50b 100644
--- a/kapi/include/kapi/memory/address.hpp
+++ b/kapi/include/kapi/memory/address.hpp
@@ -55,6 +55,25 @@ namespace kapi::memory
return std::bit_cast<std::byte *>(m_value);
}
+ //! Create a new address n beyond this one.
+ //!
+ //! @param n The amount to increase the address by.
+ //! @return A new address, n further than this one.
+ constexpr auto operator+(std::uintptr_t n) const noexcept -> address
+ {
+ return address{m_value + n};
+ }
+
+ //! Increase this address by a given amount.
+ //!
+ //! @param n The amount to increase the address by.
+ //! @return A reference to this address.
+ constexpr auto operator+=(std::uintptr_t n) noexcept -> address &
+ {
+ m_value += n;
+ return *this;
+ }
+
//! Shift this address n bits to the right.
//!
//! @param n The width of the shift.
diff --git a/kapi/include/kapi/memory/page.hpp b/kapi/include/kapi/memory/page.hpp
index 3846bd8..aa161ee 100644
--- a/kapi/include/kapi/memory/page.hpp
+++ b/kapi/include/kapi/memory/page.hpp
@@ -24,14 +24,6 @@ namespace kapi::memory
: chunk{number}
{}
- //! @copydoc chunk::containing
- //!
- //! @note This factory shadows the base factory to aid in type deduction.
- constexpr auto static containing(linear_address address) noexcept -> page
- {
- return page{chunk::containing(address)};
- }
-
//! Convert a base chunk into a page.
//!
//! This constructor allows for conversion from chunk<linear_address, PLATFORM_PAGE_SIZE> to a page for convenience.
diff --git a/kapi/include/kapi/memory/page_mapper.hpp b/kapi/include/kapi/memory/page_mapper.hpp
index 07eabcf..c6052e9 100644
--- a/kapi/include/kapi/memory/page_mapper.hpp
+++ b/kapi/include/kapi/memory/page_mapper.hpp
@@ -8,6 +8,8 @@
#include <kstd/ext/bitfield_enum>
+#include <cstddef>
+#include <cstdint>
#include <type_traits>
namespace kapi::memory
@@ -30,6 +32,7 @@ namespace kapi::memory
executable = 1 << 1, //! The page contains executable instructions.
uncached = 1 << 2, //! The page contents must not be cached.
supervisor_only = 1 << 3, //! The page is only accessible in supervisor mode.
+ global = 1 << 4, //! The page translation persists across context switches.
};
virtual ~page_mapper() = default;