aboutsummaryrefslogtreecommitdiff
path: root/arch/x86_64
diff options
context:
space:
mode:
Diffstat (limited to 'arch/x86_64')
-rw-r--r--arch/x86_64/CMakeLists.txt10
-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
-rw-r--r--arch/x86_64/kapi/cio.cpp20
-rw-r--r--arch/x86_64/kapi/cpu.cpp (renamed from arch/x86_64/src/kapi/cpu.cpp)4
-rw-r--r--arch/x86_64/kapi/memory.cpp (renamed from arch/x86_64/src/kapi/memory.cpp)64
-rw-r--r--arch/x86_64/src/boot/boot32.S2
-rw-r--r--arch/x86_64/src/boot/initialize_runtime.cpp23
-rw-r--r--arch/x86_64/src/debug/qemu_output.cpp8
-rw-r--r--arch/x86_64/src/kapi/cio.cpp20
-rw-r--r--arch/x86_64/src/memory/kernel_mapper.cpp36
-rw-r--r--arch/x86_64/src/memory/mmu.cpp12
-rw-r--r--arch/x86_64/src/memory/page_table.cpp12
-rw-r--r--arch/x86_64/src/memory/paging_root.cpp6
-rw-r--r--arch/x86_64/src/memory/recursive_page_mapper.cpp30
-rw-r--r--arch/x86_64/src/memory/region_allocator.cpp30
-rw-r--r--arch/x86_64/src/memory/scoped_mapping.cpp22
-rw-r--r--arch/x86_64/src/vga/text/buffer.cpp8
-rw-r--r--arch/x86_64/src/vga/text/device.cpp24
44 files changed, 342 insertions, 328 deletions
diff --git a/arch/x86_64/CMakeLists.txt b/arch/x86_64/CMakeLists.txt
index 519fb93..413b5aa 100644
--- a/arch/x86_64/CMakeLists.txt
+++ b/arch/x86_64/CMakeLists.txt
@@ -11,6 +11,11 @@ target_link_libraries("x86_64" PUBLIC
)
target_sources("x86_64" PRIVATE
+ # Platform-dependent KAPI implementation
+ "kapi/cio.cpp"
+ "kapi/cpu.cpp"
+ "kapi/memory.cpp"
+
# Low-level bootstrap
"src/boot/boot32.S"
"src/boot/entry64.s"
@@ -20,11 +25,6 @@ target_sources("x86_64" PRIVATE
# Debug interfaces
"src/debug/qemu_output.cpp"
- # api::kapi implementation
- "src/kapi/cio.cpp"
- "src/kapi/cpu.cpp"
- "src/kapi/memory.cpp"
-
# Memory management
"src/memory/kernel_mapper.cpp"
"src/memory/mmu.cpp"
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 memory_information
{
@@ -28,14 +28,14 @@ namespace teachos::memory::x86_64
//! This includes all sections that are marked as occupying space in the kernel executable. The internal structure
//! of this area is more described in a more fine-grained manner by the ELF symbol information provided in the
//! Multiboot2 information by the loader.
- std::pair<physical_address, physical_address> image_range;
+ std::pair<kapi::memory::physical_address, kapi::memory::physical_address> image_range;
//! The memory range occupied by the loader supplied Multiboot2 information structure.
//!
//! In general, this information is allocated somewhere in the range of the loaded image, but the loader protocol
//! does not guarantee this. It is thus imperative to be able to handle the cases where the loader chooses to
//! allocate the information structure outside of the image range.
- std::pair<physical_address, physical_address> mbi_range;
+ std::pair<kapi::memory::physical_address, kapi::memory::physical_address> mbi_range;
//! The loader supplied map of memory regions.
//!
@@ -51,33 +51,34 @@ namespace teachos::memory::x86_64
//! @param information The description of the detected memory regions as well as regions that are already occupied.
explicit region_allocator(memory_information const & information);
- //! @copydoc frame_allocator::allocate_many
+ //! @copydoc kapi::memory::frame_allocator::allocate_many
//!
//! @note As long as free frames are available, successive calls to this implementation are guaranteed to yield
//! frames in ascending order.
- 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;
- //! @copydoc frame_allocator::release_many
+ //! @copydoc kapi::memory::frame_allocator::release_many
//!
//! @note This implementation will never actually release any frames.
- 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;
- auto next_free_frame() noexcept -> std::optional<frame>;
+ auto next_free_frame() noexcept -> std::optional<kapi::memory::frame>;
private:
//! Find the next memory area and write it into current_area.
auto choose_next_region() -> void;
- auto find_next_frame() -> std::optional<frame>;
+ auto find_next_frame() -> std::optional<kapi::memory::frame>;
- frame m_next_frame; //!< The next available frame.
+ kapi::memory::frame m_next_frame; //!< The next available frame.
std::optional<region> m_current_region; //!< The memory region currently used for allocation
multiboot2::memory_map m_memory_map; //!< The boot loader supplied memory map.
- frame m_kernel_start; //!< The start of the kernel image in physical memory.
- frame m_kernel_end; //!< The end of the kernel image in physical memory.
- frame m_multiboot_start; //!< The start of the Multiboot2 information in physical memory.
- frame m_multiboot_end; //!< The end of the Multiboot2 information in physical memory.
+ kapi::memory::frame m_kernel_start; //!< The start of the kernel image in physical memory.
+ kapi::memory::frame m_kernel_end; //!< The end of the kernel image in physical memory.
+ kapi::memory::frame m_multiboot_start; //!< The start of the Multiboot2 information in physical memory.
+ kapi::memory::frame m_multiboot_end; //!< The end of the Multiboot2 information in physical memory.
};
-} // namespace teachos::memory::x86_64
+} // namespace arch::memory
-#endif // TEACHOS_ARCH_X86_64_MEMORY_ALLOCATOR_AREA_FRAME_ALLOCATOR_HPP
+#endif
diff --git a/arch/x86_64/include/x86_64/memory/scoped_mapping.hpp b/arch/x86_64/include/arch/memory/scoped_mapping.hpp
index 835e2df..c713e03 100644
--- a/arch/x86_64/include/x86_64/memory/scoped_mapping.hpp
+++ b/arch/x86_64/include/arch/memory/scoped_mapping.hpp
@@ -3,9 +3,11 @@
#include "kapi/memory.hpp"
-#include "x86_64/memory/page_table.hpp"
+#include "arch/memory/page_table.hpp"
-namespace teachos::memory::x86_64
+#include <cstddef>
+
+namespace arch::memory
{
//! A page mapping that, if established, maps a given frame to a given unused page, unmapping it on destruction. It
@@ -23,7 +25,7 @@ namespace teachos::memory::x86_64
//! Construct a new scoped mapping, which can be used to map a frame to the given unused page.
//! @param page An unused page. If the page is already mapped, this constructor will panic.
//! @param mapper The page mapper to use for mapping and unmapping of the page.
- explicit scoped_mapping(page page, page_mapper & mapper);
+ explicit scoped_mapping(kapi::memory::page page, kapi::memory::page_mapper & mapper);
//! Unmap the mapped frame if one was mapped.
//! @note Any page tables that were allocated to support the mapping will be released.
@@ -40,11 +42,11 @@ namespace teachos::memory::x86_64
//! @param frame A frame to map.
//! @param flags The flags, besides the present flag, to apply to the mapping.
//! @return A pointer to the first byte of the mapped frame.
- auto map(frame frame, page_table::entry::flags flags) -> std::byte *;
+ auto map(kapi::memory::frame frame, page_table::entry::flags flags) -> std::byte *;
//! Map the given frame, returning a typed pointer.
template<typename DataType>
- auto map_as(frame frame, page_table::entry::flags flags) -> DataType *
+ auto map_as(kapi::memory::frame frame, page_table::entry::flags flags) -> DataType *
{
return std::bit_cast<DataType *>(map(frame, flags));
}
@@ -56,11 +58,11 @@ namespace teachos::memory::x86_64
friend auto swap(scoped_mapping & lhs, scoped_mapping & rhs) -> void;
private:
- page m_page;
- page_mapper * m_mapper;
+ kapi::memory::page m_page;
+ kapi::memory::page_mapper * m_mapper;
bool m_mapped;
};
-} // namespace teachos::memory::x86_64
+} // namespace arch::memory
#endif \ No newline at end of file
diff --git a/arch/x86_64/include/x86_64/vga/crtc.hpp b/arch/x86_64/include/arch/vga/crtc.hpp
index fde69c2..dbdc365 100644
--- a/arch/x86_64/include/x86_64/vga/crtc.hpp
+++ b/arch/x86_64/include/arch/vga/crtc.hpp
@@ -1,14 +1,12 @@
#ifndef TEACHOS_X86_64_VGA_IO_HPP
#define TEACHOS_X86_64_VGA_IO_HPP
-#include "x86_64/device_io/port_io.hpp"
+#include "arch/device_io/port_io.hpp"
#include <cstddef>
-namespace teachos::vga::x86_64::crtc
+namespace arch::vga::crtc
{
- namespace io = io::x86_64;
-
/**
* @brief The address port of the CRT Controller.
*/
@@ -32,6 +30,6 @@ namespace teachos::vga::x86_64::crtc
[[maybe_unused]] constexpr auto cursor_end = std::byte{0x0b};
} // namespace registers
-} // namespace teachos::vga::x86_64::crtc
+} // namespace arch::vga::crtc
#endif \ No newline at end of file
diff --git a/arch/x86_64/include/x86_64/vga/text.hpp b/arch/x86_64/include/arch/vga/text.hpp
index f81ab60..f81ab60 100644
--- a/arch/x86_64/include/x86_64/vga/text.hpp
+++ b/arch/x86_64/include/arch/vga/text.hpp
diff --git a/arch/x86_64/include/x86_64/vga/text/attribute.hpp b/arch/x86_64/include/arch/vga/text/attribute.hpp
index 2dce708..6a0f995 100644
--- a/arch/x86_64/include/x86_64/vga/text/attribute.hpp
+++ b/arch/x86_64/include/arch/vga/text/attribute.hpp
@@ -1,12 +1,12 @@
#ifndef TEACHOS_X86_64_VGA_TEXT_ATTRIBUTE_HPP
#define TEACHOS_X86_64_VGA_TEXT_ATTRIBUTE_HPP
-// IWYU pragma: private, include "x86_64/vga/text.hpp"
+// IWYU pragma: private, include "arch/vga/text.hpp"
-#include "x86_64/vga/text/color.hpp"
-#include "x86_64/vga/text/flags.hpp"
+#include "arch/vga/text/color.hpp"
+#include "arch/vga/text/flags.hpp"
-namespace teachos::vga::x86_64::text
+namespace arch::vga::text
{
//! The VGA text mode attribute.
//!
@@ -25,6 +25,6 @@ namespace teachos::vga::x86_64::text
static_assert(sizeof(attribute) == 1, "The VGA text mode attribute must fit inside a single byte.");
-} // namespace teachos::vga::x86_64::text
+} // namespace arch::vga::text
#endif \ No newline at end of file
diff --git a/arch/x86_64/include/x86_64/vga/text/buffer.hpp b/arch/x86_64/include/arch/vga/text/buffer.hpp
index 9e93af3..648d37a 100644
--- a/arch/x86_64/include/x86_64/vga/text/buffer.hpp
+++ b/arch/x86_64/include/arch/vga/text/buffer.hpp
@@ -1,16 +1,16 @@
#ifndef TEACHOS_X86_64_VGA_TEXT_BUFFER_HPP
#define TEACHOS_X86_64_VGA_TEXT_BUFFER_HPP
-// IWYU pragma: private, include "x86_64/vga/text.hpp"
+// IWYU pragma: private, include "arch/vga/text.hpp"
-#include "x86_64/vga/text/attribute.hpp"
+#include "arch/vga/text/attribute.hpp"
#include <cstddef>
#include <span>
#include <string_view>
#include <utility>
-namespace teachos::vga::x86_64::text
+namespace arch::vga::text
{
//! A VGA text buffer.
//!
@@ -96,6 +96,6 @@ namespace teachos::vga::x86_64::text
std::size_t m_position{};
};
-} // namespace teachos::vga::x86_64::text
+} // namespace arch::vga::text
#endif \ No newline at end of file
diff --git a/arch/x86_64/include/x86_64/vga/text/color.hpp b/arch/x86_64/include/arch/vga/text/color.hpp
index 0bdc146..a541830 100644
--- a/arch/x86_64/include/x86_64/vga/text/color.hpp
+++ b/arch/x86_64/include/arch/vga/text/color.hpp
@@ -1,11 +1,11 @@
#ifndef TEACHOS_X86_64_VGA_TEXT_COLOR_HPP
#define TEACHOS_X86_64_VGA_TEXT_COLOR_HPP
-// IWYU pragma: private, include "x86_64/vga/text.hpp"
+// IWYU pragma: private, include "arch/vga/text.hpp"
#include <cstdint>
-namespace teachos::vga::x86_64::text
+namespace arch::vga::text
{
//! VGA Text Mode standard colors.
//!
@@ -30,6 +30,6 @@ namespace teachos::vga::x86_64::text
gray,
};
-} // namespace teachos::vga::x86_64::text
+} // namespace arch::vga::text
#endif \ No newline at end of file
diff --git a/arch/x86_64/include/x86_64/vga/text/common_attributes.hpp b/arch/x86_64/include/arch/vga/text/common_attributes.hpp
index f6204f3..9bd61a5 100644
--- a/arch/x86_64/include/x86_64/vga/text/common_attributes.hpp
+++ b/arch/x86_64/include/arch/vga/text/common_attributes.hpp
@@ -1,13 +1,13 @@
#ifndef TEACHOS_X86_64_VGA_TEXT_COMMON_ATTRIBUTES_HPP
#define TEACHOS_X86_64_VGA_TEXT_COMMON_ATTRIBUTES_HPP
-// IWYU pragma: private, include "x86_64/vga/text.hpp"
+// IWYU pragma: private, include "arch/vga/text.hpp"
-#include "x86_64/vga/text/attribute.hpp"
-#include "x86_64/vga/text/color.hpp"
-#include "x86_64/vga/text/flags.hpp"
+#include "arch/vga/text/attribute.hpp"
+#include "arch/vga/text/color.hpp"
+#include "arch/vga/text/flags.hpp"
-namespace teachos::vga::x86_64::text
+namespace arch::vga::text
{
//! Make the affected cell display with a gray foreground and black background.
[[maybe_unused]] constexpr auto gray_on_black = attribute{.foreground_color = color::gray,
@@ -32,6 +32,6 @@ namespace teachos::vga::x86_64::text
.foreground_flag = foreground_flag::intense,
.background_color = color::red,
.background_flag = background_flag::none};
-} // namespace teachos::vga::x86_64::text
+} // namespace arch::vga::text
#endif \ No newline at end of file
diff --git a/arch/x86_64/include/x86_64/vga/text/device.hpp b/arch/x86_64/include/arch/vga/text/device.hpp
index f5c69a1..11b3281 100644
--- a/arch/x86_64/include/x86_64/vga/text/device.hpp
+++ b/arch/x86_64/include/arch/vga/text/device.hpp
@@ -1,15 +1,15 @@
#ifndef TEACHOS_X86_64_VGA_TEXT_DEVICE_HPP
#define TEACHOS_X86_64_VGA_TEXT_DEVICE_HPP
-// IWYU pragma: private, include "x86_64/vga/text.hpp"
+// IWYU pragma: private, include "arch/vga/text.hpp"
#include "kapi/cio.hpp"
-#include "x86_64/vga/text/buffer.hpp"
+#include "arch/vga/text/buffer.hpp"
#include <string_view>
-namespace teachos::vga::x86_64::text
+namespace arch::vga::text
{
//! A VGA Text Mode device.
//!
@@ -18,7 +18,7 @@ namespace teachos::vga::x86_64::text
//! determines the visual style of that cell.
//!
//! @see text::attribute
- struct device final : teachos::cio::output_device
+ struct device final : kapi::cio::output_device
{
device();
@@ -33,13 +33,13 @@ namespace teachos::vga::x86_64::text
//! @param enabled Whether to enable the cursor.
auto cursor(bool enabled) -> void;
- //! @copydoc teachos::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:
buffer m_buffer;
};
-} // namespace teachos::vga::x86_64::text
+} // namespace arch::vga::text
#endif \ No newline at end of file
diff --git a/arch/x86_64/include/x86_64/vga/text/flags.hpp b/arch/x86_64/include/arch/vga/text/flags.hpp
index 784b910..67c6c11 100644
--- a/arch/x86_64/include/x86_64/vga/text/flags.hpp
+++ b/arch/x86_64/include/arch/vga/text/flags.hpp
@@ -1,9 +1,9 @@
#ifndef TEACHOS_X86_64_VGA_TEXT_FLAGS_HPP
#define TEACHOS_X86_64_VGA_TEXT_FLAGS_HPP
-// IWYU pragma: private, include "x86_64/vga/text.hpp"
+// IWYU pragma: private, include "arch/vga/text.hpp"
-namespace teachos::vga::x86_64::text
+namespace arch::vga::text
{
//! VGA Text Mode standard background modification flags.
@@ -33,6 +33,6 @@ namespace teachos::vga::x86_64::text
intense,
};
-} // namespace teachos::vga::x86_64::text
+} // namespace arch::vga::text
#endif \ No newline at end of file
diff --git a/arch/x86_64/include/x86_64/memory/recursive_page_mapper.hpp b/arch/x86_64/include/x86_64/memory/recursive_page_mapper.hpp
deleted file mode 100644
index 819f404..0000000
--- a/arch/x86_64/include/x86_64/memory/recursive_page_mapper.hpp
+++ /dev/null
@@ -1,25 +0,0 @@
-#ifndef TEACHOS_X86_64_RECURSIVE_PAGE_MAPPER_HPP
-#define TEACHOS_X86_64_RECURSIVE_PAGE_MAPPER_HPP
-
-#include "kapi/memory.hpp"
-
-#include <cstddef>
-
-namespace teachos::memory::x86_64
-{
-
- struct recursive_page_mapper : page_mapper
- {
- explicit recursive_page_mapper(frame_allocator & allocator);
-
- auto map(page page, frame frame, flags flags) -> std::byte * override;
- auto unmap(page page) -> void override;
- auto try_unmap(page page) noexcept -> bool override;
-
- private:
- frame_allocator * m_allocator;
- };
-
-} // namespace teachos::memory::x86_64
-
-#endif \ No newline at end of file
diff --git a/arch/x86_64/kapi/cio.cpp b/arch/x86_64/kapi/cio.cpp
new file mode 100644
index 0000000..015cf5e
--- /dev/null
+++ b/arch/x86_64/kapi/cio.cpp
@@ -0,0 +1,20 @@
+#include "kapi/cio.hpp"
+
+#include "arch/debug/qemu_output.hpp"
+#include "arch/vga/text.hpp"
+
+#include <optional>
+
+namespace kapi::cio
+{
+
+ auto static constinit vga_device = std::optional<arch::vga::text::device>{};
+ auto static constinit dbg_device = std::optional<arch::debug::qemu_output>{};
+
+ auto init() -> void
+ {
+ vga_device.emplace().cursor(false);
+ set_output_device(dbg_device.emplace(*vga_device));
+ }
+
+} // namespace kapi::cio
diff --git a/arch/x86_64/src/kapi/cpu.cpp b/arch/x86_64/kapi/cpu.cpp
index 22543ee..2a0f8f7 100644
--- a/arch/x86_64/src/kapi/cpu.cpp
+++ b/arch/x86_64/kapi/cpu.cpp
@@ -1,6 +1,6 @@
#include "kapi/cpu.hpp"
-namespace teachos::cpu
+namespace kapi::cpu
{
auto halt() -> void
@@ -9,4 +9,4 @@ namespace teachos::cpu
__builtin_unreachable();
}
-} // namespace teachos::cpu
+} // namespace kapi::cpu
diff --git a/arch/x86_64/src/kapi/memory.cpp b/arch/x86_64/kapi/memory.cpp
index e2681a6..e366ee1 100644
--- a/arch/x86_64/src/kapi/memory.cpp
+++ b/arch/x86_64/kapi/memory.cpp
@@ -3,18 +3,18 @@
#include "kapi/boot.hpp"
#include "kapi/system.hpp"
-#include "x86_64/boot/boot.hpp"
-#include "x86_64/boot/ld.hpp"
-#include "x86_64/cpu/registers.hpp"
-#include "x86_64/memory/buffered_allocator.hpp"
-#include "x86_64/memory/kernel_mapper.hpp"
-#include "x86_64/memory/mmu.hpp"
-#include "x86_64/memory/page_table.hpp"
-#include "x86_64/memory/page_utilities.hpp"
-#include "x86_64/memory/paging_root.hpp"
-#include "x86_64/memory/recursive_page_mapper.hpp"
-#include "x86_64/memory/region_allocator.hpp"
-#include "x86_64/memory/scoped_mapping.hpp"
+#include "arch/boot/boot.hpp"
+#include "arch/boot/ld.hpp"
+#include "arch/cpu/registers.hpp"
+#include "arch/memory/buffered_allocator.hpp"
+#include "arch/memory/kernel_mapper.hpp"
+#include "arch/memory/mmu.hpp"
+#include "arch/memory/page_table.hpp"
+#include "arch/memory/page_utilities.hpp"
+#include "arch/memory/paging_root.hpp"
+#include "arch/memory/recursive_page_mapper.hpp"
+#include "arch/memory/region_allocator.hpp"
+#include "arch/memory/scoped_mapping.hpp"
#include <kstd/print>
@@ -29,13 +29,13 @@
#include <span>
#include <utility>
-namespace teachos::memory
+namespace kapi::memory
{
namespace
{
constexpr auto static unused_page_address = linear_address{0x0000'7fff'cafe'faceuz};
- constexpr auto static recursive_page_map_index = x86_64::page_table::entry_count - 2;
+ constexpr auto static recursive_page_map_index = arch::memory::page_table::entry_count - 2;
//! Instantiate a basic, memory region based, early frame allocator for remapping.
auto collect_memory_information()
@@ -48,9 +48,9 @@ namespace teachos::memory
auto const & mbi = boot::bootstrap_information.mbi;
auto mbi_span = std::span{std::bit_cast<std::byte *>(mbi), mbi->size_bytes()};
- auto image_span = std::span{&boot::x86_64::_start_physical, &boot::x86_64::_end_physical};
+ auto image_span = std::span{&arch::boot::_start_physical, &arch::boot::_end_physical};
- return x86_64::region_allocator::memory_information{
+ return arch::memory::region_allocator::memory_information{
.image_range = std::make_pair(physical_address{&image_span.front()}, physical_address{&image_span.back()}),
.mbi_range = std::make_pair(physical_address{&mbi_span.front()}, physical_address{&mbi_span.back()}),
.memory_map = *memory_map,
@@ -60,19 +60,21 @@ namespace teachos::memory
//! Enable additional CPU protection features, required during later stages of the kernel.
auto enable_cpu_protections() -> void
{
- cpu::x86_64::cr0::set(cpu::x86_64::cr0::flags::write_protect);
- cpu::x86_64::i32_efer::set(cpu::x86_64::i32_efer::flags::execute_disable_bit_enable);
+ arch::cpu::cr0::set(arch::cpu::cr0::flags::write_protect);
+ arch::cpu::i32_efer::set(arch::cpu::i32_efer::flags::execute_disable_bit_enable);
}
//! Inject, or graft, a faux recursive PML4 into the active page mapping structure.
auto inject_faux_pml4(frame_allocator & allocator, page_mapper & mapper)
{
- using namespace x86_64;
- using entry_flags = page_table::entry::flags;
+ using arch::memory::page_table;
+ using arch::memory::paging_root;
+ using arch::memory::pml_index;
+ using entry_flags = arch::memory::page_table::entry::flags;
auto page = page::containing(unused_page_address);
- auto temporary_mapper = scoped_mapping{page, mapper};
+ auto temporary_mapper = arch::memory::scoped_mapping{page, mapper};
auto new_pml4_frame = allocator.allocate();
auto pml4 = std::construct_at(temporary_mapper.map_as<page_table>(*new_pml4_frame, entry_flags::writable));
@@ -97,7 +99,7 @@ namespace teachos::memory
(*paging_root::get())[recursive_page_map_index].frame(new_pml4_frame.value(),
entry_flags::present | entry_flags::writable);
- tlb_flush_all();
+ arch::memory::tlb_flush_all();
auto new_pml4 = paging_root::get();
(*new_pml4)[pml4_index] = pml4_entry;
@@ -116,7 +118,7 @@ namespace teachos::memory
auto remap_kernel(page_mapper & mapper) -> void
{
- auto kernel_mapper = x86_64::kernel_mapper{boot::bootstrap_information.mbi};
+ auto kernel_mapper = arch::memory::kernel_mapper{boot::bootstrap_information.mbi};
kernel_mapper.remap_kernel(mapper);
}
@@ -124,7 +126,7 @@ namespace teachos::memory
{
constexpr auto vga_base = std::uintptr_t{0xb8000};
auto vga_physical_start = physical_address{vga_base};
- auto vga_virtual_start = linear_address{vga_base + std::bit_cast<std::uintptr_t>(&boot::x86_64::TEACHOS_VMA)};
+ auto vga_virtual_start = linear_address{vga_base + std::bit_cast<std::uintptr_t>(&arch::boot::TEACHOS_VMA)};
auto page = page::containing(vga_virtual_start);
auto frame = frame::containing(vga_physical_start);
@@ -136,7 +138,7 @@ namespace teachos::memory
{
auto mbi_base = std::bit_cast<std::uintptr_t>(boot::bootstrap_information.mbi);
auto mbi_size = boot::bootstrap_information.mbi->size_bytes();
- auto mbi_physical_start = physical_address{mbi_base & ~std::bit_cast<std::uintptr_t>(&boot::x86_64::TEACHOS_VMA)};
+ auto mbi_physical_start = physical_address{mbi_base & ~std::bit_cast<std::uintptr_t>(&arch::boot::TEACHOS_VMA)};
auto mbi_virtual_start = linear_address{mbi_base};
auto mbi_block_count = (mbi_size + PLATFORM_FRAME_SIZE - 1) / PLATFORM_FRAME_SIZE;
@@ -148,9 +150,9 @@ namespace teachos::memory
}
}
- auto constinit region_based_allocator = std::optional<x86_64::region_allocator>{};
- auto constinit buffered_allocator = std::optional<x86_64::buffered_allocator<4>>{};
- auto constinit recursive_page_mapper = std::optional<x86_64::recursive_page_mapper>{};
+ auto constinit region_based_allocator = std::optional<arch::memory::region_allocator>{};
+ auto constinit buffered_allocator = std::optional<arch::memory::buffered_allocator<4>>{};
+ auto constinit recursive_page_mapper = std::optional<arch::memory::recursive_page_mapper>{};
} // namespace
@@ -181,12 +183,12 @@ namespace teachos::memory
kstd::println("[x86_64:MEM] Switching to new paging hierarchy.");
- auto cr3 = cpu::x86_64::cr3::read();
+ auto cr3 = arch::cpu::cr3::read();
cr3.frame(new_pml4_frame);
- cpu::x86_64::cr3::write(cr3);
+ arch::cpu::cr3::write(cr3);
set_frame_allocator(*buffered_allocator);
set_page_mapper(*recursive_page_mapper);
}
-} // namespace teachos::memory
+} // namespace kapi::memory
diff --git a/arch/x86_64/src/boot/boot32.S b/arch/x86_64/src/boot/boot32.S
index 0e164e2..056cd8e 100644
--- a/arch/x86_64/src/boot/boot32.S
+++ b/arch/x86_64/src/boot/boot32.S
@@ -1,4 +1,4 @@
-#include "x86_64/boot/boot.hpp"
+#include "arch/boot/boot.hpp"
/**
* @brief Uninitialized data for the bootstrapping process.
diff --git a/arch/x86_64/src/boot/initialize_runtime.cpp b/arch/x86_64/src/boot/initialize_runtime.cpp
index f413448..b08c13c 100644
--- a/arch/x86_64/src/boot/initialize_runtime.cpp
+++ b/arch/x86_64/src/boot/initialize_runtime.cpp
@@ -2,16 +2,21 @@
#include <functional>
#include <span>
-extern "C"
+namespace arch::boot
{
- using global_initializer = auto (*)() -> void;
- extern global_initializer __init_array_start;
- extern global_initializer __init_array_end;
-
- auto invoke_global_constructors() -> void
+ extern "C"
{
- auto initializers = std::span{&__init_array_start, &__init_array_end};
- std::ranges::for_each(initializers, [](auto invokable) { std::invoke(invokable); });
+ using global_initializer = auto (*)() -> void;
+
+ extern global_initializer __init_array_start;
+ extern global_initializer __init_array_end;
+
+ auto invoke_global_constructors() -> void
+ {
+ auto initializers = std::span{&__init_array_start, &__init_array_end};
+ std::ranges::for_each(initializers, [](auto invokable) { std::invoke(invokable); });
+ }
}
-}
+
+} // namespace arch::boot \ No newline at end of file
diff --git a/arch/x86_64/src/debug/qemu_output.cpp b/arch/x86_64/src/debug/qemu_output.cpp
index 0af5bdc..535017d 100644
--- a/arch/x86_64/src/debug/qemu_output.cpp
+++ b/arch/x86_64/src/debug/qemu_output.cpp
@@ -1,11 +1,11 @@
-#include "x86_64/debug/qemu_output.hpp"
+#include "arch/debug/qemu_output.hpp"
#include "kapi/cio.hpp"
#include <algorithm>
#include <string_view>
-namespace teachos::debug::x86_64
+namespace arch::debug
{
qemu_output::qemu_output(output_device & lower)
@@ -13,7 +13,7 @@ namespace teachos::debug::x86_64
, m_present{port::read() == port::address}
{}
- auto qemu_output::write(cio::output_stream stream, std::string_view text) -> void
+ auto qemu_output::write(kapi::cio::output_stream stream, std::string_view text) -> void
{
if (m_present)
{
@@ -22,4 +22,4 @@ namespace teachos::debug::x86_64
m_lower.write(stream, text);
}
-} // namespace teachos::debug::x86_64
+} // namespace arch::debug
diff --git a/arch/x86_64/src/kapi/cio.cpp b/arch/x86_64/src/kapi/cio.cpp
deleted file mode 100644
index 5594fcc..0000000
--- a/arch/x86_64/src/kapi/cio.cpp
+++ /dev/null
@@ -1,20 +0,0 @@
-#include "kapi/cio.hpp"
-
-#include "x86_64/debug/qemu_output.hpp"
-#include "x86_64/vga/text.hpp"
-
-#include <optional>
-
-namespace teachos::cio
-{
-
- auto static constinit vga_device = std::optional<vga::x86_64::text::device>{};
- auto static constinit dbg_device = std::optional<debug::x86_64::qemu_output>{};
-
- auto init() -> void
- {
- vga_device.emplace().cursor(false);
- set_output_device(dbg_device.emplace(*vga_device));
- }
-
-} // namespace teachos::cio
diff --git a/arch/x86_64/src/memory/kernel_mapper.cpp b/arch/x86_64/src/memory/kernel_mapper.cpp
index 89b2e83..08c32c5 100644
--- a/arch/x86_64/src/memory/kernel_mapper.cpp
+++ b/arch/x86_64/src/memory/kernel_mapper.cpp
@@ -1,9 +1,9 @@
-#include "x86_64/memory/kernel_mapper.hpp"
+#include "arch/memory/kernel_mapper.hpp"
#include "kapi/memory.hpp"
#include "kapi/system.hpp"
-#include "x86_64/boot/ld.hpp"
+#include "arch/boot/ld.hpp"
#include <kstd/print>
@@ -19,7 +19,7 @@
#include <string_view>
#include <utility>
-namespace teachos::memory::x86_64
+namespace arch::memory
{
namespace
@@ -39,15 +39,15 @@ namespace teachos::memory::x86_64
kernel_mapper::kernel_mapper(multiboot2::information_view const * mbi)
: m_mbi{std::move(mbi)}
- , m_kernel_load_base{std::bit_cast<std::uintptr_t>(&boot::x86_64::TEACHOS_VMA)}
+ , m_kernel_load_base{std::bit_cast<std::uintptr_t>(&arch::boot::TEACHOS_VMA)}
{}
- auto kernel_mapper::remap_kernel(page_mapper & mapper) -> void
+ auto kernel_mapper::remap_kernel(kapi::memory::page_mapper & mapper) -> void
{
auto elf_information = m_mbi->maybe_elf_symbols<elf::format::elf64>();
if (!elf_information)
{
- system::panic("[x86_64:MEM] ELF section information is not available.");
+ kapi::system::panic("[x86_64:MEM] ELF section information is not available.");
}
auto sections = *elf_information;
@@ -61,38 +61,38 @@ namespace teachos::memory::x86_64
if (allocated_sections.empty())
{
- system::panic("[x86_64:MEM] No allocated ELF sections were found.");
+ kapi::system::panic("[x86_64:MEM] No allocated ELF sections were found.");
}
std::ranges::for_each(allocated_sections,
[&](auto const & section) -> auto { map_section(section, sections.name(section), mapper); });
}
- auto kernel_mapper::map_section(section_header_type const & section, std::string_view name, page_mapper & mapper)
- -> void
+ auto kernel_mapper::map_section(section_header_type const & section, std::string_view name,
+ kapi::memory::page_mapper & mapper) -> void
{
auto number_of_pages = (section.size + (PLATFORM_PAGE_SIZE - 1)) / PLATFORM_PAGE_SIZE;
- auto linear_start_address = linear_address{section.virtual_load_address};
- auto physical_start_address = physical_address{section.virtual_load_address & ~m_kernel_load_base};
+ auto linear_start_address = kapi::memory::linear_address{section.virtual_load_address};
+ auto physical_start_address = kapi::memory::physical_address{section.virtual_load_address & ~m_kernel_load_base};
kstd::println("[x86_64:MEM] mapping {}"
"\n {} bytes -> page count: {}"
"\n {} @ {}",
name, section.size, number_of_pages, linear_start_address, physical_start_address);
- auto first_page = page::containing(linear_start_address);
- auto first_frame = frame::containing(physical_start_address);
+ auto first_page = kapi::memory::page::containing(linear_start_address);
+ auto first_frame = kapi::memory::frame::containing(physical_start_address);
- auto page_flags = page_mapper::flags::empty;
+ auto page_flags = kapi::memory::page_mapper::flags::empty;
if (section.writable())
{
- page_flags |= page_mapper::flags::writable;
+ page_flags |= kapi::memory::page_mapper::flags::writable;
}
if (section.executable())
{
- page_flags |= page_mapper::flags::executable;
+ page_flags |= kapi::memory::page_mapper::flags::executable;
}
auto is_prefix_of_name = [=](auto prefix) -> bool {
@@ -101,7 +101,7 @@ namespace teachos::memory::x86_64
if (!std::ranges::any_of(user_accessible_prefixes, is_prefix_of_name))
{
- page_flags |= page_mapper::flags::supervisor_only;
+ page_flags |= kapi::memory::page_mapper::flags::supervisor_only;
}
for (auto i = 0uz; i < number_of_pages; ++i)
@@ -110,4 +110,4 @@ namespace teachos::memory::x86_64
}
}
-} // namespace teachos::memory::x86_64 \ No newline at end of file
+} // namespace arch::memory \ No newline at end of file
diff --git a/arch/x86_64/src/memory/mmu.cpp b/arch/x86_64/src/memory/mmu.cpp
index e15d94e..ea23278 100644
--- a/arch/x86_64/src/memory/mmu.cpp
+++ b/arch/x86_64/src/memory/mmu.cpp
@@ -1,14 +1,12 @@
-#include "x86_64/memory/mmu.hpp"
+#include "arch/memory/mmu.hpp"
#include "kapi/memory.hpp"
-#include "x86_64/cpu/registers.hpp"
+#include "arch/cpu/registers.hpp"
-namespace teachos::memory::x86_64
+namespace arch::memory
{
- namespace cpu = cpu::x86_64;
-
- auto tlb_flush(linear_address address) -> void
+ auto tlb_flush(kapi::memory::linear_address address) -> void
{
asm volatile("invlpg (%[input])" : /* no output from call */ : [input] "r"(address) : "memory");
}
@@ -18,4 +16,4 @@ namespace teachos::memory::x86_64
auto paging_root = cpu::cr3::read();
cpu::cr3::write(paging_root);
}
-} // namespace teachos::memory::x86_64
+} // namespace arch::memory
diff --git a/arch/x86_64/src/memory/page_table.cpp b/arch/x86_64/src/memory/page_table.cpp
index 2de099d..26cdd29 100644
--- a/arch/x86_64/src/memory/page_table.cpp
+++ b/arch/x86_64/src/memory/page_table.cpp
@@ -1,4 +1,4 @@
-#include "x86_64/memory/page_table.hpp"
+#include "arch/memory/page_table.hpp"
#include "kapi/memory.hpp"
@@ -9,7 +9,7 @@
#include <optional>
#include <utility>
-namespace teachos::memory::x86_64
+namespace arch::memory
{
auto page_table::entry::clear() noexcept -> void
@@ -44,16 +44,16 @@ namespace teachos::memory::x86_64
return *this;
}
- auto page_table::entry::frame() const noexcept -> std::optional<struct frame>
+ auto page_table::entry::frame() const noexcept -> std::optional<kapi::memory::frame>
{
if (present())
{
- return frame::containing(physical_address{m_raw & frame_number_mask});
+ return kapi::memory::frame::containing(kapi::memory::physical_address{m_raw & frame_number_mask});
}
return std::nullopt;
}
- auto page_table::entry::frame(struct frame frame, flags flags) noexcept -> void
+ auto page_table::entry::frame(kapi::memory::frame frame, flags flags) noexcept -> void
{
m_raw = (frame.start_address().raw() | static_cast<std::uint64_t>(flags));
};
@@ -79,4 +79,4 @@ namespace teachos::memory::x86_64
[](auto const & entry) -> auto { return entry.all_flags() == entry::flags::empty; });
}
-} // namespace teachos::memory::x86_64
+} // namespace arch::memory
diff --git a/arch/x86_64/src/memory/paging_root.cpp b/arch/x86_64/src/memory/paging_root.cpp
index d849a82..41f40ed 100644
--- a/arch/x86_64/src/memory/paging_root.cpp
+++ b/arch/x86_64/src/memory/paging_root.cpp
@@ -1,9 +1,9 @@
-#include "x86_64/memory/paging_root.hpp"
+#include "arch/memory/paging_root.hpp"
#include <bit>
#include <cstdint>
-namespace teachos::memory::x86_64
+namespace arch::memory
{
namespace
@@ -16,4 +16,4 @@ namespace teachos::memory::x86_64
return std::bit_cast<paging_root *>(recursive_base);
}
-} // namespace teachos::memory::x86_64 \ No newline at end of file
+} // namespace arch::memory \ No newline at end of file
diff --git a/arch/x86_64/src/memory/recursive_page_mapper.cpp b/arch/x86_64/src/memory/recursive_page_mapper.cpp
index c5aabcb..d8273e1 100644
--- a/arch/x86_64/src/memory/recursive_page_mapper.cpp
+++ b/arch/x86_64/src/memory/recursive_page_mapper.cpp
@@ -1,16 +1,16 @@
-#include "x86_64/memory/recursive_page_mapper.hpp"
+#include "arch/memory/recursive_page_mapper.hpp"
#include "kapi/memory.hpp"
#include "kapi/system.hpp"
-#include "x86_64/memory/page_table.hpp"
-#include "x86_64/memory/page_utilities.hpp"
-#include "x86_64/memory/paging_root.hpp"
+#include "arch/memory/page_table.hpp"
+#include "arch/memory/page_utilities.hpp"
+#include "arch/memory/paging_root.hpp"
#include <cstddef>
#include <optional>
-namespace teachos::memory::x86_64
+namespace arch::memory
{
namespace
{
@@ -22,7 +22,8 @@ namespace teachos::memory::x86_64
//! added, thus still enforcing non-writability and non-execution of the affected page.
template<std::size_t Level>
requires(Level > 1uz && Level <= PLATFORM_PAGING_LEVELS)
- auto do_map(recursive_page_table<Level> * pml, page page, frame_allocator & allocator, page_mapper::flags flags)
+ auto do_map(recursive_page_table<Level> * pml, kapi::memory::page page, kapi::memory::frame_allocator & allocator,
+ kapi::memory::page_mapper::flags flags)
{
auto index = pml_index<Level>(page);
auto entry_flags = to_table_flags(flags);
@@ -41,12 +42,13 @@ namespace teachos::memory::x86_64
}
//! Perform the actual PML1 update.
- auto do_map(page_table * pml, page page, frame frame, page_mapper::flags flags) -> std::optional<std::byte *>
+ auto do_map(page_table * pml, kapi::memory::page page, kapi::memory::frame frame,
+ kapi::memory::page_mapper::flags flags) -> std::optional<std::byte *>
{
auto index = pml_index<1>(page);
if ((*pml)[index].present())
{
- system::panic("[x86_64:MEM] Tried to map a page that is already mapped");
+ kapi::system::panic("[x86_64:MEM] Tried to map a page that is already mapped");
}
(*pml)[index].frame(frame, page_table::entry::flags::present | to_table_flags(flags));
return std::optional{static_cast<std::byte *>(page.start_address())};
@@ -54,11 +56,11 @@ namespace teachos::memory::x86_64
} // namespace
- recursive_page_mapper::recursive_page_mapper(frame_allocator & allocator)
+ recursive_page_mapper::recursive_page_mapper(kapi::memory::frame_allocator & allocator)
: m_allocator{&allocator}
{}
- auto recursive_page_mapper::map(page page, frame frame, flags flags) -> std::byte *
+ auto recursive_page_mapper::map(kapi::memory::page page, kapi::memory::frame frame, flags flags) -> std::byte *
{
auto pml4 = static_cast<recursive_page_table<4> *>((paging_root::get()));
@@ -70,15 +72,15 @@ namespace teachos::memory::x86_64
.value_or(nullptr);
}
- auto recursive_page_mapper::unmap(page page) -> void
+ auto recursive_page_mapper::unmap(kapi::memory::page page) -> void
{
if (!try_unmap(page))
{
- system::panic("[x86_64:MEM] Tried to unmap a page that was not mapped.");
+ kapi::system::panic("[x86_64:MEM] Tried to unmap a page that was not mapped.");
}
}
- auto recursive_page_mapper::try_unmap(page page) noexcept -> bool
+ auto recursive_page_mapper::try_unmap(kapi::memory::page page) noexcept -> bool
{
if (!paging_root::get()->translate(page))
{
@@ -116,4 +118,4 @@ namespace teachos::memory::x86_64
return true;
}
-} // namespace teachos::memory::x86_64 \ No newline at end of file
+} // namespace arch::memory \ No newline at end of file
diff --git a/arch/x86_64/src/memory/region_allocator.cpp b/arch/x86_64/src/memory/region_allocator.cpp
index 7a8fb8b..a2dfd48 100644
--- a/arch/x86_64/src/memory/region_allocator.cpp
+++ b/arch/x86_64/src/memory/region_allocator.cpp
@@ -1,4 +1,4 @@
-#include "x86_64/memory/region_allocator.hpp"
+#include "arch/memory/region_allocator.hpp"
#include "kapi/memory/address.hpp"
#include "kapi/memory/frame.hpp"
@@ -11,16 +11,17 @@
#include <ranges>
#include <utility>
-namespace teachos::memory::x86_64
+namespace arch::memory
{
namespace
{
constexpr auto last_frame(multiboot2::memory_map::region const & region)
{
- return frame::containing(physical_address{region.base + region.size_in_B - 1});
+ return kapi::memory::frame::containing(kapi::memory::physical_address{region.base + region.size_in_B - 1});
}
- constexpr auto falls_within(frame const & candidate, frame const & start, frame const & end)
+ constexpr auto falls_within(kapi::memory::frame const & candidate, kapi::memory::frame const & start,
+ kapi::memory::frame const & end)
{
return candidate >= start && candidate <= end;
}
@@ -30,10 +31,10 @@ namespace teachos::memory::x86_64
: m_next_frame{}
, m_current_region{}
, m_memory_map{mem_info.memory_map}
- , m_kernel_start(frame::containing(mem_info.image_range.first))
- , m_kernel_end(frame::containing(mem_info.image_range.second))
- , m_multiboot_start(frame::containing(mem_info.mbi_range.first))
- , m_multiboot_end(frame::containing(mem_info.mbi_range.second))
+ , m_kernel_start{kapi::memory::frame::containing(mem_info.image_range.first)}
+ , m_kernel_end{kapi::memory::frame::containing(mem_info.image_range.second)}
+ , m_multiboot_start{kapi::memory::frame::containing(mem_info.mbi_range.first)}
+ , m_multiboot_end{kapi::memory::frame::containing(mem_info.mbi_range.second)}
{
choose_next_region();
}
@@ -56,14 +57,14 @@ namespace teachos::memory::x86_64
}
m_current_region = *lowest_region;
- if (auto start_of_region = frame::containing(physical_address{m_current_region->base});
+ if (auto start_of_region = kapi::memory::frame::containing(kapi::memory::physical_address{m_current_region->base});
start_of_region > m_next_frame)
{
m_next_frame = start_of_region;
}
}
- auto region_allocator::find_next_frame() -> std::optional<frame>
+ auto region_allocator::find_next_frame() -> std::optional<kapi::memory::frame>
{
if (!m_current_region || m_next_frame > last_frame(*m_current_region))
{
@@ -97,7 +98,8 @@ namespace teachos::memory::x86_64
return m_current_region.transform([this](auto) -> auto { return m_next_frame; });
}
- auto region_allocator::allocate_many(std::size_t count) noexcept -> std::optional<std::pair<frame, std::size_t>>
+ auto region_allocator::allocate_many(std::size_t count) noexcept
+ -> std::optional<std::pair<kapi::memory::frame, std::size_t>>
{
while (m_current_region)
{
@@ -122,11 +124,11 @@ namespace teachos::memory::x86_64
return std::nullopt;
}
- auto region_allocator::release_many(std::pair<frame, std::size_t>) -> void {}
+ auto region_allocator::release_many(std::pair<kapi::memory::frame, std::size_t>) -> void {}
- auto region_allocator::next_free_frame() noexcept -> std::optional<frame>
+ auto region_allocator::next_free_frame() noexcept -> std::optional<kapi::memory::frame>
{
return find_next_frame();
}
-} // namespace teachos::memory::x86_64
+} // namespace arch::memory
diff --git a/arch/x86_64/src/memory/scoped_mapping.cpp b/arch/x86_64/src/memory/scoped_mapping.cpp
index 945183d..dde1dda 100644
--- a/arch/x86_64/src/memory/scoped_mapping.cpp
+++ b/arch/x86_64/src/memory/scoped_mapping.cpp
@@ -1,32 +1,32 @@
-#include "x86_64/memory/scoped_mapping.hpp"
+#include "arch/memory/scoped_mapping.hpp"
#include "kapi/memory.hpp"
#include "kapi/system.hpp"
-#include "x86_64/memory/mmu.hpp"
-#include "x86_64/memory/page_table.hpp"
-#include "x86_64/memory/paging_root.hpp"
+#include "arch/memory/mmu.hpp"
+#include "arch/memory/page_table.hpp"
+#include "arch/memory/paging_root.hpp"
#include <cstddef>
#include <utility>
-namespace teachos::memory::x86_64
+namespace arch::memory
{
scoped_mapping::scoped_mapping(scoped_mapping && other) noexcept
- : m_page{std::exchange(other.m_page, page{})}
+ : m_page{std::exchange(other.m_page, kapi::memory::page{})}
, m_mapper{std::exchange(other.m_mapper, nullptr)}
, m_mapped{std::exchange(other.m_mapped, false)}
{}
- scoped_mapping::scoped_mapping(page page, page_mapper & mapper)
+ scoped_mapping::scoped_mapping(kapi::memory::page page, kapi::memory::page_mapper & mapper)
: m_page{page}
, m_mapper{&mapper}
, m_mapped{false}
{
if (paging_root::get()->translate(page))
{
- system::panic("[MEM] Tried to map a page that is already mapped!");
+ kapi::system::panic("[MEM] Tried to map a page that is already mapped!");
}
}
@@ -35,7 +35,7 @@ namespace teachos::memory::x86_64
if (m_mapped)
{
unmap();
- x86_64::tlb_flush(m_page.start_address());
+ tlb_flush(m_page.start_address());
}
}
@@ -45,7 +45,7 @@ namespace teachos::memory::x86_64
return *this;
}
- auto scoped_mapping::map(frame frame, page_table::entry::flags flags) -> std::byte *
+ auto scoped_mapping::map(kapi::memory::frame frame, page_table::entry::flags flags) -> std::byte *
{
auto result = m_mapper->map(m_page, frame, to_mapper_flags(flags));
m_mapped = true;
@@ -66,4 +66,4 @@ namespace teachos::memory::x86_64
swap(lhs.m_mapped, rhs.m_mapped);
}
-} // namespace teachos::memory::x86_64 \ No newline at end of file
+} // namespace arch::memory \ No newline at end of file
diff --git a/arch/x86_64/src/vga/text/buffer.cpp b/arch/x86_64/src/vga/text/buffer.cpp
index 2dcf084..7112573 100644
--- a/arch/x86_64/src/vga/text/buffer.cpp
+++ b/arch/x86_64/src/vga/text/buffer.cpp
@@ -1,6 +1,6 @@
-#include "x86_64/vga/text/buffer.hpp"
+#include "arch/vga/text/buffer.hpp"
-#include "x86_64/vga/text/attribute.hpp"
+#include "arch/vga/text/attribute.hpp"
#include <algorithm>
#include <bit>
@@ -9,7 +9,7 @@
#include <string_view>
#include <utility>
-namespace teachos::vga::x86_64::text
+namespace arch::vga::text
{
buffer::buffer(std::size_t width, std::size_t height, cell * start, std::size_t position)
: m_width{width}
@@ -98,4 +98,4 @@ namespace teachos::vga::x86_64::text
m_buffer[m_position++] = std::pair{code_point, std::bit_cast<std::byte>(attribute)};
}
-} // namespace teachos::vga::x86_64::text
+} // namespace arch::vga::text
diff --git a/arch/x86_64/src/vga/text/device.cpp b/arch/x86_64/src/vga/text/device.cpp
index 2da9e06..dcacd8c 100644
--- a/arch/x86_64/src/vga/text/device.cpp
+++ b/arch/x86_64/src/vga/text/device.cpp
@@ -1,16 +1,16 @@
#include "kapi/cio.hpp"
-#include "x86_64/boot/boot.hpp"
-#include "x86_64/boot/ld.hpp"
-#include "x86_64/vga/crtc.hpp"
-#include "x86_64/vga/text.hpp"
+#include "arch/boot/boot.hpp"
+#include "arch/boot/ld.hpp"
+#include "arch/vga/crtc.hpp"
+#include "arch/vga/text.hpp"
#include <bit>
#include <cstddef>
#include <cstdint>
#include <string_view>
-namespace teachos::vga::x86_64::text
+namespace arch::vga::text
{
namespace
{
@@ -22,10 +22,10 @@ namespace teachos::vga::x86_64::text
} // namespace
device::device()
- : m_buffer{default_buffer_width, default_buffer_height,
- std::bit_cast<buffer::cell *>(default_buffer_address +
- std::bit_cast<std::uintptr_t>(&teachos::boot::x86_64::TEACHOS_VMA)),
- boot::bootstrap_information.vga_buffer_index}
+ : m_buffer{
+ default_buffer_width, default_buffer_height,
+ std::bit_cast<buffer::cell *>(default_buffer_address + std::bit_cast<std::uintptr_t>(&boot::TEACHOS_VMA)),
+ kapi::boot::bootstrap_information.vga_buffer_index}
{
clear();
}
@@ -43,12 +43,12 @@ namespace teachos::vga::x86_64::text
crtc::data::write(crtc::data::read() | cursor_disable_byte);
}
- auto device::write(cio::output_stream stream, std::string_view text) -> void
+ auto device::write(kapi::cio::output_stream stream, std::string_view text) -> void
{
auto attributes = [&] -> attribute {
switch (stream)
{
- case cio::output_stream::stderr:
+ case kapi::cio::output_stream::stderr:
return red_on_black;
default:
return green_on_black;
@@ -57,4 +57,4 @@ namespace teachos::vga::x86_64::text
m_buffer.write(text, attributes);
}
-} // namespace teachos::vga::x86_64::text
+} // namespace arch::vga::text