aboutsummaryrefslogtreecommitdiff
path: root/arch/x86_64/include
diff options
context:
space:
mode:
authorFelix Morgner <felix.morgner@ost.ch>2026-01-16 13:36:38 +0100
committerFelix Morgner <felix.morgner@ost.ch>2026-01-16 13:36:38 +0100
commit7d6f0ed063790042a808f4bf07c50d308b3f2de4 (patch)
tree1a2e1c4ed7e2f3d8e6cdcfb012e554d1a4eb1e5a /arch/x86_64/include
parent9750405757396d006ab6992fb93baf414b3e2ae8 (diff)
downloadteachos-7d6f0ed063790042a808f4bf07c50d308b3f2de4.tar.xz
teachos-7d6f0ed063790042a808f4bf07c50d308b3f2de4.zip
chore: restructure namespaces
Diffstat (limited to 'arch/x86_64/include')
-rw-r--r--arch/x86_64/include/arch/boot/boot.hpp (renamed from arch/x86_64/include/x86_64/boot/boot.hpp)4
-rw-r--r--arch/x86_64/include/arch/boot/ld.hpp (renamed from arch/x86_64/include/x86_64/boot/ld.hpp)4
-rw-r--r--arch/x86_64/include/arch/cpu/control_register.hpp (renamed from arch/x86_64/include/x86_64/cpu/control_register.hpp)26
-rw-r--r--arch/x86_64/include/arch/cpu/interrupts.hpp (renamed from arch/x86_64/include/x86_64/cpu/interrupts.hpp)6
-rw-r--r--arch/x86_64/include/arch/cpu/model_specific_register.hpp (renamed from arch/x86_64/include/x86_64/cpu/model_specific_register.hpp)14
-rw-r--r--arch/x86_64/include/arch/cpu/registers.hpp (renamed from arch/x86_64/include/x86_64/cpu/registers.hpp)10
-rw-r--r--arch/x86_64/include/arch/cpu/segment_selector.hpp (renamed from arch/x86_64/include/x86_64/cpu/segment_selector.hpp)5
-rw-r--r--arch/x86_64/include/arch/debug/qemu_output.hpp (renamed from arch/x86_64/include/x86_64/debug/qemu_output.hpp)14
-rw-r--r--arch/x86_64/include/arch/device_io/port_io.hpp (renamed from arch/x86_64/include/x86_64/device_io/port_io.hpp)4
-rw-r--r--arch/x86_64/include/arch/memory/buffered_allocator.hpp (renamed from arch/x86_64/include/x86_64/memory/buffered_allocator.hpp)15
-rw-r--r--arch/x86_64/include/arch/memory/kernel_mapper.hpp (renamed from arch/x86_64/include/x86_64/memory/kernel_mapper.hpp)9
-rw-r--r--arch/x86_64/include/arch/memory/mmu.hpp (renamed from arch/x86_64/include/x86_64/memory/mmu.hpp)6
-rw-r--r--arch/x86_64/include/arch/memory/page_table.hpp (renamed from arch/x86_64/include/x86_64/memory/page_table.hpp)43
-rw-r--r--arch/x86_64/include/arch/memory/page_utilities.hpp (renamed from arch/x86_64/include/x86_64/memory/page_utilities.hpp)6
-rw-r--r--arch/x86_64/include/arch/memory/paging_root.hpp (renamed from arch/x86_64/include/x86_64/memory/paging_root.hpp)6
-rw-r--r--arch/x86_64/include/arch/memory/recursive_page_mapper.hpp25
-rw-r--r--arch/x86_64/include/arch/memory/region_allocator.hpp (renamed from arch/x86_64/include/x86_64/memory/region_allocator.hpp)35
-rw-r--r--arch/x86_64/include/arch/memory/scoped_mapping.hpp (renamed from arch/x86_64/include/x86_64/memory/scoped_mapping.hpp)18
-rw-r--r--arch/x86_64/include/arch/vga/crtc.hpp (renamed from arch/x86_64/include/x86_64/vga/crtc.hpp)8
-rw-r--r--arch/x86_64/include/arch/vga/text.hpp (renamed from arch/x86_64/include/x86_64/vga/text.hpp)0
-rw-r--r--arch/x86_64/include/arch/vga/text/attribute.hpp (renamed from arch/x86_64/include/x86_64/vga/text/attribute.hpp)10
-rw-r--r--arch/x86_64/include/arch/vga/text/buffer.hpp (renamed from arch/x86_64/include/x86_64/vga/text/buffer.hpp)8
-rw-r--r--arch/x86_64/include/arch/vga/text/color.hpp (renamed from arch/x86_64/include/x86_64/vga/text/color.hpp)6
-rw-r--r--arch/x86_64/include/arch/vga/text/common_attributes.hpp (renamed from arch/x86_64/include/x86_64/vga/text/common_attributes.hpp)12
-rw-r--r--arch/x86_64/include/arch/vga/text/device.hpp (renamed from arch/x86_64/include/x86_64/vga/text/device.hpp)14
-rw-r--r--arch/x86_64/include/arch/vga/text/flags.hpp (renamed from arch/x86_64/include/x86_64/vga/text/flags.hpp)6
-rw-r--r--arch/x86_64/include/x86_64/memory/recursive_page_mapper.hpp25
27 files changed, 172 insertions, 167 deletions
diff --git a/arch/x86_64/include/x86_64/boot/boot.hpp b/arch/x86_64/include/arch/boot/boot.hpp
index 2c44659..71e8a70 100644
--- a/arch/x86_64/include/x86_64/boot/boot.hpp
+++ b/arch/x86_64/include/arch/boot/boot.hpp
@@ -51,7 +51,7 @@
#include <cstddef>
-namespace teachos::boot
+namespace kapi::boot
{
struct information
@@ -63,7 +63,7 @@ namespace teachos::boot
std::size_t vga_buffer_index;
};
-} // namespace teachos::boot
+} // namespace kapi::boot
#endif
diff --git a/arch/x86_64/include/x86_64/boot/ld.hpp b/arch/x86_64/include/arch/boot/ld.hpp
index b073863..988723d 100644
--- a/arch/x86_64/include/x86_64/boot/ld.hpp
+++ b/arch/x86_64/include/arch/boot/ld.hpp
@@ -17,7 +17,7 @@
#include <cstddef>
-namespace teachos::boot::x86_64
+namespace arch::boot
{
extern "C"
@@ -56,6 +56,6 @@ namespace teachos::boot::x86_64
extern std::byte TEACHOS_VMA;
}
-} // namespace teachos::boot::x86_64
+} // namespace arch::boot
#endif
diff --git a/arch/x86_64/include/x86_64/cpu/control_register.hpp b/arch/x86_64/include/arch/cpu/control_register.hpp
index 67ae87e..681dc5f 100644
--- a/arch/x86_64/include/x86_64/cpu/control_register.hpp
+++ b/arch/x86_64/include/arch/cpu/control_register.hpp
@@ -1,7 +1,7 @@
-#ifndef TEACHOS_X86_64_CPU_IMPL_CONTROL_REGISTERS_HPP
-#define TEACHOS_X86_64_CPU_IMPL_CONTROL_REGISTERS_HPP
+#ifndef TEACHOS_X86_64_CPU_CONTROL_REGISTERS_HPP
+#define TEACHOS_X86_64_CPU_CONTROL_REGISTERS_HPP
-// IWYU pragma: private, include "x86_64/cpu/registers.hpp"
+// IWYU pragma: private, include "arch/cpu/registers.hpp"
#include "kapi/memory.hpp"
@@ -12,7 +12,7 @@
#include <type_traits>
#include <utility>
-namespace teachos::cpu::x86_64
+namespace arch::cpu
{
namespace impl
{
@@ -58,22 +58,22 @@ namespace teachos::cpu::x86_64
page_level_write_through = 1uz << 0,
page_level_cache_disable = 1uz << 1,
};
-} // namespace teachos::cpu::x86_64
+} // namespace arch::cpu
namespace kstd::ext
{
template<>
- struct is_bitfield_enum<teachos::cpu::x86_64::cr0_flags> : std::true_type
+ struct is_bitfield_enum<arch::cpu::cr0_flags> : std::true_type
{
};
template<>
- struct is_bitfield_enum<teachos::cpu::x86_64::cr3_flags> : std::true_type
+ struct is_bitfield_enum<arch::cpu::cr3_flags> : std::true_type
{
};
} // namespace kstd::ext
-namespace teachos::cpu::x86_64
+namespace arch::cpu
{
//! A mixin for flag-oriented control registers.
//!
@@ -173,7 +173,7 @@ namespace teachos::cpu::x86_64
//!
//! @param address The physical address of the root page map
//! @param flags The root configuration flags of the paging system.
- constexpr cr3_value(memory::physical_address address, cr3_flags flags = static_cast<cr3_flags>(0))
+ constexpr cr3_value(kapi::memory::physical_address address, cr3_flags flags = static_cast<cr3_flags>(0))
: m_flags{static_cast<std::uint64_t>(flags)}
, m_address{static_cast<std::uint64_t>(address.raw())}
{}
@@ -181,15 +181,15 @@ namespace teachos::cpu::x86_64
//! Extract the physical address of the root page map from this value.
//!
//! @return The physical address of the root page map.
- [[nodiscard]] constexpr auto address() const -> memory::physical_address
+ [[nodiscard]] constexpr auto address() const -> kapi::memory::physical_address
{
- return memory::physical_address{m_address};
+ return kapi::memory::physical_address{m_address};
}
//! Encode the frame aligned physical address of the root page map into this value.
//!
//! @param frame The frame containing a PML4.
- constexpr auto frame(memory::frame frame) -> void
+ constexpr auto frame(kapi::memory::frame frame) -> void
{
m_address = static_cast<std::uint64_t>(frame.number());
}
@@ -243,6 +243,6 @@ namespace teachos::cpu::x86_64
static_assert(sizeof(cr3_value) == sizeof(std::uint64_t));
-} // namespace teachos::cpu::x86_64
+} // namespace arch::cpu
#endif \ No newline at end of file
diff --git a/arch/x86_64/include/x86_64/cpu/interrupts.hpp b/arch/x86_64/include/arch/cpu/interrupts.hpp
index 88d0b78..92c5824 100644
--- a/arch/x86_64/include/x86_64/cpu/interrupts.hpp
+++ b/arch/x86_64/include/arch/cpu/interrupts.hpp
@@ -1,13 +1,13 @@
#ifndef TEACHOS_X86_64_CPU_INTERRUPTS_HPP
#define TEACHOS_X86_64_CPU_INTERRUPTS_HPP
-#include "x86_64/cpu/segment_selector.hpp"
+#include "arch/cpu/segment_selector.hpp"
#include <array>
#include <cstdint>
#include <type_traits>
-namespace teachos::cpu::x86_64
+namespace arch::cpu
{
//! The types of supported gates.
@@ -56,6 +56,6 @@ namespace teachos::cpu::x86_64
std::array<gate_descriptor, 256> m_descriptors{};
};
-} // namespace teachos::cpu::x86_64
+} // namespace arch::cpu
#endif \ No newline at end of file
diff --git a/arch/x86_64/include/x86_64/cpu/model_specific_register.hpp b/arch/x86_64/include/arch/cpu/model_specific_register.hpp
index 39765fe..8539a24 100644
--- a/arch/x86_64/include/x86_64/cpu/model_specific_register.hpp
+++ b/arch/x86_64/include/arch/cpu/model_specific_register.hpp
@@ -1,5 +1,5 @@
-#ifndef TEACHOS_X86_64_CPU_IMPL_MODEL_SPECIFIC_REGISTER_HPP
-#define TEACHOS_X86_64_CPU_IMPL_MODEL_SPECIFIC_REGISTER_HPP
+#ifndef TEACHOS_X86_64_CPU_MODEL_SPECIFIC_REGISTER_HPP
+#define TEACHOS_X86_64_CPU_MODEL_SPECIFIC_REGISTER_HPP
// IWYU pragma: private, include "x86_64/cpu/registers.hpp"
@@ -9,7 +9,7 @@
#include <cstdint>
#include <type_traits>
-namespace teachos::cpu::x86_64
+namespace arch::cpu
{
//! The flags of the IA32_EFER (Extended Features Enable Register) MSR.
@@ -25,19 +25,19 @@ namespace teachos::cpu::x86_64
execute_disable_bit_enable = 1uz << 11,
};
-} // namespace teachos::cpu::x86_64
+} // namespace arch::cpu
namespace kstd::ext
{
template<>
- struct is_bitfield_enum<teachos::cpu::x86_64::ia32_efer_flags> : std::true_type
+ struct is_bitfield_enum<arch::cpu::ia32_efer_flags> : std::true_type
{
};
} // namespace kstd::ext
-namespace teachos::cpu::x86_64
+namespace arch::cpu
{
//! The MSR number for the IA32_EFER MSR
constexpr auto ia32_efer_number = 0xC000'0080u;
@@ -146,6 +146,6 @@ namespace teachos::cpu::x86_64
}
};
-} // namespace teachos::cpu::x86_64
+} // namespace arch::cpu
#endif \ No newline at end of file
diff --git a/arch/x86_64/include/x86_64/cpu/registers.hpp b/arch/x86_64/include/arch/cpu/registers.hpp
index 3ddd539..d7def10 100644
--- a/arch/x86_64/include/x86_64/cpu/registers.hpp
+++ b/arch/x86_64/include/arch/cpu/registers.hpp
@@ -3,10 +3,10 @@
#include "kapi/memory.hpp"
-#include "x86_64/cpu/control_register.hpp" // IWYU pragma: export
-#include "x86_64/cpu/model_specific_register.hpp" // IWYU pragma: export
+#include "arch/cpu/control_register.hpp" // IWYU pragma: export
+#include "arch/cpu/model_specific_register.hpp" // IWYU pragma: export
-namespace teachos::cpu::x86_64
+namespace arch::cpu
{
//! Configuration Register 0.
@@ -17,7 +17,7 @@ namespace teachos::cpu::x86_64
//! Configuration Register 2.
//!
//! This configuration register holds the memory address the access to which has triggered the most recent page fault.
- using cr2 = control_register<memory::linear_address, &impl::cr2_asm>;
+ using cr2 = control_register<kapi::memory::linear_address, &impl::cr2_asm>;
//! Configuration Register 3.
//!
@@ -27,6 +27,6 @@ namespace teachos::cpu::x86_64
//! The I32_EFER (Extended Feature Enable Register) MSR
using i32_efer = model_specific_register<ia32_efer_number, ia32_efer_flags>;
-} // namespace teachos::cpu::x86_64
+} // namespace arch::cpu
#endif \ No newline at end of file
diff --git a/arch/x86_64/include/x86_64/cpu/segment_selector.hpp b/arch/x86_64/include/arch/cpu/segment_selector.hpp
index bb07e28..1a78c47 100644
--- a/arch/x86_64/include/x86_64/cpu/segment_selector.hpp
+++ b/arch/x86_64/include/arch/cpu/segment_selector.hpp
@@ -2,7 +2,8 @@
#define TEACHOS_X86_64_SEGMENT_SELECTOR_HPP
#include <cstdint>
-namespace teachos::cpu::x86_64
+
+namespace arch::cpu
{
struct segment_selector
@@ -15,6 +16,6 @@ namespace teachos::cpu::x86_64
static_assert(sizeof(segment_selector) == sizeof(std::uint16_t));
static_assert(alignof(segment_selector) == alignof(std::uint16_t));
-} // namespace teachos::cpu::x86_64
+} // namespace arch::cpu
#endif \ No newline at end of file
diff --git a/arch/x86_64/include/x86_64/debug/qemu_output.hpp b/arch/x86_64/include/arch/debug/qemu_output.hpp
index 61b47d6..e72eb39 100644
--- a/arch/x86_64/include/x86_64/debug/qemu_output.hpp
+++ b/arch/x86_64/include/arch/debug/qemu_output.hpp
@@ -3,11 +3,11 @@
#include "kapi/cio.hpp"
-#include "x86_64/device_io/port_io.hpp"
+#include "arch/device_io/port_io.hpp"
#include <string_view>
-namespace teachos::debug::x86_64
+namespace arch::debug
{
//! A QEMU debug console output device.
@@ -18,18 +18,18 @@ namespace teachos::debug::x86_64
//! @note Support for the device has to be enabled when the emulator is started. The device will try to detect if the
//! port is available. If the port is detected, any output to the device will be written to port before being
//! forwarded to the lower device.
- struct qemu_output : cio::output_device
+ struct qemu_output : kapi::cio::output_device
{
//! The port to write to.
- using port = io::x86_64::port<0xE9, unsigned char, io::x86_64::port_write, io::x86_64::port_read>;
+ using port = io::port<0xE9, unsigned char, io::port_write, io::port_read>;
//! Construct a new debug device wrapper for the given output device.
//!
//! @param lower The device to forward the output to.
explicit qemu_output(output_device & lower);
- //! @copydoc cio::output_device
- auto write(cio::output_stream stream, std::string_view text) -> void override;
+ //! @copydoc kapi::cio::output_device
+ auto write(kapi::cio::output_stream stream, std::string_view text) -> void override;
private:
//! The device to forward the output to.
@@ -38,6 +38,6 @@ namespace teachos::debug::x86_64
bool m_present;
};
-} // namespace teachos::debug::x86_64
+} // namespace arch::debug
#endif \ No newline at end of file
diff --git a/arch/x86_64/include/x86_64/device_io/port_io.hpp b/arch/x86_64/include/arch/device_io/port_io.hpp
index fa2ec2d..65e58e3 100644
--- a/arch/x86_64/include/x86_64/device_io/port_io.hpp
+++ b/arch/x86_64/include/arch/device_io/port_io.hpp
@@ -8,7 +8,7 @@
#include <string_view>
#include <type_traits>
-namespace teachos::io::x86_64
+namespace arch::io
{
//! The requirements imposed on a type usable for port I/O.
@@ -102,6 +102,6 @@ namespace teachos::io::x86_64
: std::string_view{"eax"};
};
-} // namespace teachos::io::x86_64
+} // namespace arch::io
#endif \ No newline at end of file
diff --git a/arch/x86_64/include/x86_64/memory/buffered_allocator.hpp b/arch/x86_64/include/arch/memory/buffered_allocator.hpp
index fa3b5cb..87ebbf6 100644
--- a/arch/x86_64/include/x86_64/memory/buffered_allocator.hpp
+++ b/arch/x86_64/include/arch/memory/buffered_allocator.hpp
@@ -10,11 +10,11 @@
#include <optional>
#include <utility>
-namespace teachos::memory::x86_64
+namespace arch::memory
{
template<std::size_t BufferSize>
- struct buffered_allocator : frame_allocator
+ struct buffered_allocator : kapi::memory::frame_allocator
{
explicit buffered_allocator(frame_allocator * underlying)
: m_underlying{underlying}
@@ -23,7 +23,7 @@ namespace teachos::memory::x86_64
auto from_underlying = m_underlying->allocate_many(BufferSize);
if (!from_underlying)
{
- system::panic("[x86_64:MEM] Not enough frames available from underlying allocator.");
+ kapi::system::panic("[x86_64:MEM] Not enough frames available from underlying allocator.");
}
auto [first_frame, count] = *from_underlying;
std::ranges::generate_n(m_pool.begin(), count, [first_frame]() mutable { return first_frame++; });
@@ -45,7 +45,8 @@ namespace teachos::memory::x86_64
auto operator=(buffered_allocator const &) = delete;
auto operator=(buffered_allocator &&) = delete;
- auto allocate_many(std::size_t count = 1) noexcept -> std::optional<std::pair<frame, std::size_t>> override
+ auto allocate_many(std::size_t count = 1) noexcept
+ -> std::optional<std::pair<kapi::memory::frame, std::size_t>> override
{
if (count > m_free)
{
@@ -87,7 +88,7 @@ namespace teachos::memory::x86_64
return m_underlying->allocate_many(count);
}
- auto release_many(std::pair<frame, std::size_t> frame_set) -> void override
+ auto release_many(std::pair<kapi::memory::frame, std::size_t> frame_set) -> void override
{
if (m_free == BufferSize)
{
@@ -129,9 +130,9 @@ namespace teachos::memory::x86_64
frame_allocator * m_underlying;
std::size_t m_free;
- std::array<std::optional<frame>, BufferSize> m_pool{};
+ std::array<std::optional<kapi::memory::frame>, BufferSize> m_pool{};
};
-} // namespace teachos::memory::x86_64
+} // namespace arch::memory
#endif \ No newline at end of file
diff --git a/arch/x86_64/include/x86_64/memory/kernel_mapper.hpp b/arch/x86_64/include/arch/memory/kernel_mapper.hpp
index c393d73..4329f1b 100644
--- a/arch/x86_64/include/x86_64/memory/kernel_mapper.hpp
+++ b/arch/x86_64/include/arch/memory/kernel_mapper.hpp
@@ -10,7 +10,7 @@
#include <cstdint>
#include <string_view>
-namespace teachos::memory::x86_64
+namespace arch::memory
{
struct kernel_mapper
@@ -19,15 +19,16 @@ namespace teachos::memory::x86_64
explicit kernel_mapper(multiboot2::information_view const * mbi);
- auto remap_kernel(page_mapper & mapper) -> void;
+ auto remap_kernel(kapi::memory::page_mapper & mapper) -> void;
private:
- auto map_section(section_header_type const & section, std::string_view name, page_mapper & mapper) -> void;
+ auto map_section(section_header_type const & section, std::string_view name, kapi::memory::page_mapper & mapper)
+ -> void;
multiboot2::information_view const * m_mbi;
std::uintptr_t m_kernel_load_base;
};
-} // namespace teachos::memory::x86_64
+} // namespace arch::memory
#endif \ No newline at end of file
diff --git a/arch/x86_64/include/x86_64/memory/mmu.hpp b/arch/x86_64/include/arch/memory/mmu.hpp
index 323d18a..2d64184 100644
--- a/arch/x86_64/include/x86_64/memory/mmu.hpp
+++ b/arch/x86_64/include/arch/memory/mmu.hpp
@@ -3,7 +3,7 @@
#include "kapi/memory/address.hpp"
-namespace teachos::memory::x86_64
+namespace arch::memory
{
/**
* @brief Invalidates any translation lookaside buffer (TLB) entry for the page table the given address is cotained
@@ -12,7 +12,7 @@ namespace teachos::memory::x86_64
* @param address Memory address, which will be used to determine the contained page and flush the TLB entry for
* that page.
*/
- auto tlb_flush(linear_address address) -> void;
+ auto tlb_flush(kapi::memory::linear_address address) -> void;
/**
* @brief Invalidates the translation lookaside buffer (TLB) entry for all page tables.
@@ -22,6 +22,6 @@ namespace teachos::memory::x86_64
*/
auto tlb_flush_all() -> void;
-} // namespace teachos::memory::x86_64
+} // namespace arch::memory
#endif \ No newline at end of file
diff --git a/arch/x86_64/include/x86_64/memory/page_table.hpp b/arch/x86_64/include/arch/memory/page_table.hpp
index 71ba5b7..a82d9e0 100644
--- a/arch/x86_64/include/x86_64/memory/page_table.hpp
+++ b/arch/x86_64/include/arch/memory/page_table.hpp
@@ -3,7 +3,7 @@
#include "kapi/memory.hpp"
-#include "x86_64/memory/page_utilities.hpp"
+#include "arch/memory/page_utilities.hpp"
#include <kstd/ext/bitfield_enum>
@@ -15,7 +15,7 @@
#include <type_traits>
#include <utility>
-namespace teachos::memory::x86_64
+namespace arch::memory
{
//! A table containing page mapping entries.
@@ -97,13 +97,13 @@ namespace teachos::memory::x86_64
//! Get the frame number associated with this entry, if the referenced page is present.
//!
//! @return an engaged std::optional iff. this entry maps a page, std::nullopt otherwise.
- [[nodiscard]] auto frame() const noexcept -> std::optional<frame>;
+ [[nodiscard]] auto frame() const noexcept -> std::optional<kapi::memory::frame>;
//! Map this entry.
//!
//! @param frame The frame to map in this entry.
//! @param flags The flags to apply to this entry.
- auto frame(struct frame frame, flags flags) noexcept -> void;
+ auto frame(kapi::memory::frame frame, flags flags) noexcept -> void;
private:
//! A mask to retrieve, or exclude, the frame number from the raw entry.
@@ -119,7 +119,7 @@ namespace teachos::memory::x86_64
};
//! The maximum number of entries in this table.
- constexpr auto static entry_count{page::size / sizeof(entry)};
+ constexpr auto static entry_count{kapi::memory::page::size / sizeof(entry)};
//! Get the entry at the given index.
//!
@@ -185,16 +185,17 @@ namespace teachos::memory::x86_64
});
}
- [[nodiscard]] auto translate(linear_address address) const -> std::optional<physical_address>
+ [[nodiscard]] auto translate(kapi::memory::linear_address address) const
+ -> std::optional<kapi::memory::physical_address>
requires(Level == 4)
{
- auto offset = address.raw() % page::size;
- return translate(page::containing(address)).transform([offset](auto frame) -> auto {
- return physical_address{frame.start_address().raw() + offset};
+ auto offset = address.raw() % kapi::memory::page::size;
+ return translate(kapi::memory::page::containing(address)).transform([offset](auto frame) -> auto {
+ return kapi::memory::physical_address{frame.start_address().raw() + offset};
});
}
- [[nodiscard]] auto translate(page page) const -> std::optional<frame>
+ [[nodiscard]] auto translate(kapi::memory::page page) const -> std::optional<kapi::memory::frame>
requires(Level == 4)
{
auto pml3 = next(pml_index<4>(page));
@@ -204,7 +205,7 @@ namespace teachos::memory::x86_64
return std::nullopt;
}
- auto handle_huge_page = [&] -> std::optional<frame> {
+ auto handle_huge_page = [&] -> std::optional<kapi::memory::frame> {
auto pml3_entry = pml3.transform([&](auto pml3) -> auto { return (*pml3)[pml_index<3>(page)]; });
if (!pml3_entry)
{
@@ -213,7 +214,7 @@ namespace teachos::memory::x86_64
else if (pml3_entry->huge())
{
auto pml3_entry_frame = *pml3_entry->frame();
- return frame{pml3_entry_frame.number() + pml_index<2>(page) * entry_count + pml_index<1>(page)};
+ return kapi::memory::frame{pml3_entry_frame.number() + pml_index<2>(page) * entry_count + pml_index<1>(page)};
}
auto pml2 = (*pml3)->next(pml_index<3>(page));
@@ -225,7 +226,7 @@ namespace teachos::memory::x86_64
else if (pml2_entry->huge())
{
auto pml2_entry_frame = *pml2_entry->frame();
- return frame{pml2_entry_frame.number() + pml_index<1>(page)};
+ return kapi::memory::frame{pml2_entry_frame.number() + pml_index<1>(page)};
}
return std::nullopt;
@@ -263,23 +264,23 @@ namespace teachos::memory::x86_64
}
};
-} // namespace teachos::memory::x86_64
+} // namespace arch::memory
namespace kstd::ext
{
template<>
- struct is_bitfield_enum<teachos::memory::x86_64::page_table::entry::flags> : std::true_type
+ struct is_bitfield_enum<arch::memory::page_table::entry::flags> : std::true_type
{
};
} // namespace kstd::ext
-namespace teachos::memory::x86_64
+namespace arch::memory
{
- constexpr auto to_mapper_flags(page_table::entry::flags flags) -> page_mapper::flags
+ constexpr auto to_mapper_flags(page_table::entry::flags flags) -> kapi::memory::page_mapper::flags
{
using table_flags = page_table::entry::flags;
- using mapper_flags = page_mapper::flags;
+ using mapper_flags = kapi::memory::page_mapper::flags;
auto result = mapper_flags{};
@@ -306,10 +307,10 @@ namespace teachos::memory::x86_64
return result;
}
- constexpr auto to_table_flags(page_mapper::flags flags) -> page_table::entry::flags
+ constexpr auto to_table_flags(kapi::memory::page_mapper::flags flags) -> page_table::entry::flags
{
using table_flags = page_table::entry::flags;
- using mapper_flags = page_mapper::flags;
+ using mapper_flags = kapi::memory::page_mapper::flags;
auto result = table_flags{};
@@ -336,6 +337,6 @@ namespace teachos::memory::x86_64
return result;
}
-} // namespace teachos::memory::x86_64
+} // namespace arch::memory
#endif \ No newline at end of file
diff --git a/arch/x86_64/include/x86_64/memory/page_utilities.hpp b/arch/x86_64/include/arch/memory/page_utilities.hpp
index efd1b80..8c25af3 100644
--- a/arch/x86_64/include/x86_64/memory/page_utilities.hpp
+++ b/arch/x86_64/include/arch/memory/page_utilities.hpp
@@ -5,18 +5,18 @@
#include <cstddef>
-namespace teachos::memory::x86_64
+namespace arch::memory
{
template<std::size_t Level>
requires(Level > 0uz && Level < 5uz)
- constexpr auto pml_index(page page) noexcept -> std::size_t
+ constexpr auto pml_index(kapi::memory::page page) noexcept -> std::size_t
{
constexpr auto shift_width = (Level - 1) * 9;
constexpr auto index_mask = 0x1ffuz;
return page.number() >> shift_width & index_mask;
}
-} // namespace teachos::memory::x86_64
+} // namespace arch::memory
#endif \ No newline at end of file
diff --git a/arch/x86_64/include/x86_64/memory/paging_root.hpp b/arch/x86_64/include/arch/memory/paging_root.hpp
index 47ee2f9..febbb11 100644
--- a/arch/x86_64/include/x86_64/memory/paging_root.hpp
+++ b/arch/x86_64/include/arch/memory/paging_root.hpp
@@ -1,9 +1,9 @@
#ifndef TEACHOS_X86_64_PAGING_ROOT_HPP
#define TEACHOS_X86_64_PAGING_ROOT_HPP
-#include "x86_64/memory/page_table.hpp"
+#include "arch/memory/page_table.hpp"
-namespace teachos::memory::x86_64
+namespace arch::memory
{
//! The active, recursively mapped, root map (e.g. PML4)
@@ -22,6 +22,6 @@ namespace teachos::memory::x86_64
paging_root() = default;
};
-} // namespace teachos::memory::x86_64
+} // namespace arch::memory
#endif \ No newline at end of file
diff --git a/arch/x86_64/include/arch/memory/recursive_page_mapper.hpp b/arch/x86_64/include/arch/memory/recursive_page_mapper.hpp
new file mode 100644
index 0000000..e278a6d
--- /dev/null
+++ b/arch/x86_64/include/arch/memory/recursive_page_mapper.hpp
@@ -0,0 +1,25 @@
+#ifndef TEACHOS_X86_64_RECURSIVE_PAGE_MAPPER_HPP
+#define TEACHOS_X86_64_RECURSIVE_PAGE_MAPPER_HPP
+
+#include "kapi/memory.hpp"
+
+#include <cstddef>
+
+namespace arch::memory
+{
+
+ struct recursive_page_mapper : kapi::memory::page_mapper
+ {
+ explicit recursive_page_mapper(kapi::memory::frame_allocator & allocator);
+
+ auto map(kapi::memory::page page, kapi::memory::frame frame, flags flags) -> std::byte * override;
+ auto unmap(kapi::memory::page page) -> void override;
+ auto try_unmap(kapi::memory::page page) noexcept -> bool override;
+
+ private:
+ kapi::memory::frame_allocator * m_allocator;
+ };
+
+} // namespace arch::memory
+
+#endif \ No newline at end of file
diff --git a/arch/x86_64/include/x86_64/memory/region_allocator.hpp b/arch/x86_64/include/arch/memory/region_allocator.hpp
index 4063bcc..f391293 100644
--- a/arch/x86_64/include/x86_64/memory/region_allocator.hpp
+++ b/arch/x86_64/include/arch/memory/region_allocator.hpp
@@ -11,7 +11,7 @@
#include <optional>
#include <utility>
-namespace teachos::memory::x86_64
+namespace arch::memory
{
//! A simple, memory-region based frame allocator.
//!
@@ -19,7 +19,7 @@ namespace teachos::memory::x86_64
//! frames occupied by the kernel image or any bootloader provided data.
//!
//! @note This allocator will never release frames.
- struct region_allocator final : frame_allocator
+ struct region_allocator final : kapi::memory::frame_allocator
{
struct memor