aboutsummaryrefslogtreecommitdiff
path: root/arch/x86_64/src/memory
diff options
context:
space:
mode:
Diffstat (limited to 'arch/x86_64/src/memory')
-rw-r--r--arch/x86_64/src/memory/frame_allocator.cpp19
-rw-r--r--arch/x86_64/src/memory/paging.cpp13
2 files changed, 24 insertions, 8 deletions
diff --git a/arch/x86_64/src/memory/frame_allocator.cpp b/arch/x86_64/src/memory/frame_allocator.cpp
index 01dcc88..70276ae 100644
--- a/arch/x86_64/src/memory/frame_allocator.cpp
+++ b/arch/x86_64/src/memory/frame_allocator.cpp
@@ -4,8 +4,6 @@
namespace teachos::arch::memory
{
- uint64_t PAGE_SIZE;
-
physical_frame::physical_frame(std::size_t frame_number)
: frame_number(frame_number)
{
@@ -17,7 +15,7 @@ namespace teachos::arch::memory
return physical_frame{address / PAGE_FRAME_SIZE};
}
- auto physical_frame::start_address() const -> uint64_t { return frame_number * PAGE_SIZE; }
+ auto physical_frame::start_address() const -> uint64_t { return frame_number * PAGE_FRAME_SIZE; }
memory_area_iterator::memory_area_iterator(memory_area * p)
: ptr(p)
@@ -39,6 +37,21 @@ namespace teachos::arch::memory
return *this;
}
+ area_frame_allocator::area_frame_allocator(std::size_t kernel_start, std::size_t kernel_end,
+ std::size_t multiboot_start, std::size_t multiboot_end,
+ memory_area * memory_areas, uint8_t area_count)
+ : next_free_frame(0)
+ , current_area(std::nullopt)
+ , area_begin(memory_areas)
+ , area_end(memory_areas + area_count)
+ , kernel_start(physical_frame::containing_address(kernel_start))
+ , kernel_end(physical_frame::containing_address(kernel_end))
+ , multiboot_start(physical_frame::containing_address(multiboot_start))
+ , multiboot_end(physical_frame::containing_address(multiboot_end))
+ {
+ choose_next_area();
+ }
+
auto area_frame_allocator::choose_next_area() -> void
{
current_area = std::nullopt;
diff --git a/arch/x86_64/src/memory/paging.cpp b/arch/x86_64/src/memory/paging.cpp
index 2f78da8..a07b2c0 100644
--- a/arch/x86_64/src/memory/paging.cpp
+++ b/arch/x86_64/src/memory/paging.cpp
@@ -42,12 +42,9 @@ namespace teachos::arch::memory
auto page_table::zero_entries() -> void
{
- auto begin = &entries[0];
- auto end = &entries[PAGE_TABLE_ENTRY_COUNT];
-
- for (auto entry = begin; entry < end; ++entry)
+ for (size_t i = 0; i < sizeof(entries) / sizeof(entries[0]); ++i)
{
- entry->set_unused();
+ entries[i].set_unused();
}
}
@@ -75,4 +72,10 @@ namespace teachos::arch::memory
return std::nullopt;
}
+
+ entry & page_table::operator[](std::size_t index)
+ {
+ arch::exception_handling::assert(index < PAGE_TABLE_ENTRY_COUNT, "[Page Table] index out of bounds");
+ return entries[index];
+ }
} // namespace teachos::arch::memory