aboutsummaryrefslogtreecommitdiff
path: root/arch/x86_64/src
diff options
context:
space:
mode:
Diffstat (limited to 'arch/x86_64/src')
-rw-r--r--arch/x86_64/src/memory/allocator/area_frame_allocator.cpp4
-rw-r--r--arch/x86_64/src/memory/allocator/physical_frame.cpp5
-rw-r--r--arch/x86_64/src/memory/multiboot/reader.cpp15
-rw-r--r--arch/x86_64/src/memory/paging/page_entry.cpp4
-rw-r--r--arch/x86_64/src/memory/paging/page_table.cpp6
-rw-r--r--arch/x86_64/src/memory/paging/virtual_page.cpp22
6 files changed, 36 insertions, 20 deletions
diff --git a/arch/x86_64/src/memory/allocator/area_frame_allocator.cpp b/arch/x86_64/src/memory/allocator/area_frame_allocator.cpp
index 9c344d8..c2cafce 100644
--- a/arch/x86_64/src/memory/allocator/area_frame_allocator.cpp
+++ b/arch/x86_64/src/memory/allocator/area_frame_allocator.cpp
@@ -87,8 +87,8 @@ namespace teachos::arch::memory::allocator
auto area_frame_allocator::deallocate_frame(physical_frame physical_frame) -> void
{
- arch::exception_handling::assert(false && physical_frame.frame_number == 0,
- "[deallocate_frame] Not implemented Exception");
+ exception_handling::assert(false && physical_frame.frame_number == 0,
+ "[deallocate_frame] Not implemented Exception");
}
auto area_frame_allocator::begin() -> multiboot::memory_area_iterator { return area_begin; }
diff --git a/arch/x86_64/src/memory/allocator/physical_frame.cpp b/arch/x86_64/src/memory/allocator/physical_frame.cpp
index 03ec193..03bd965 100644
--- a/arch/x86_64/src/memory/allocator/physical_frame.cpp
+++ b/arch/x86_64/src/memory/allocator/physical_frame.cpp
@@ -2,11 +2,6 @@
namespace teachos::arch::memory::allocator
{
- namespace
- {
- constexpr std::size_t PAGE_FRAME_SIZE = 4096U; ///< Default page size of x86_84 is always 4KiB.
- }
-
physical_frame::physical_frame(std::size_t frame_number)
: frame_number(frame_number)
{
diff --git a/arch/x86_64/src/memory/multiboot/reader.cpp b/arch/x86_64/src/memory/multiboot/reader.cpp
index 8741b44..156b437 100644
--- a/arch/x86_64/src/memory/multiboot/reader.cpp
+++ b/arch/x86_64/src/memory/multiboot/reader.cpp
@@ -19,7 +19,7 @@ namespace teachos::arch::memory::multiboot
{
auto expected_entry_size = mminfo->entry_size;
constexpr auto actual_entry_size = sizeof(memory_area);
- arch::exception_handling::assert(expected_entry_size == actual_entry_size, "Unexpected memory_area entry size");
+ exception_handling::assert(expected_entry_size == actual_entry_size, "Unexpected memory_area entry size");
auto total_size = mminfo->info.size;
auto total_entries_size = total_size - sizeof(memory_map_header) + actual_entry_size;
@@ -34,19 +34,18 @@ namespace teachos::arch::memory::multiboot
{
auto expected_entry_size = symbol->entry_size;
constexpr auto actual_entry_size = sizeof(elf_section_header);
- arch::exception_handling::assert(expected_entry_size == actual_entry_size,
- "Unexpected elf_section_header entry size");
+ exception_handling::assert(expected_entry_size == actual_entry_size, "Unexpected elf_section_header entry size");
auto expected_total_size = symbol->info.size;
auto actual_total_entry_size = actual_entry_size * symbol->number_of_sections;
constexpr auto actual_total_section_size = sizeof(elf_symbols_section_header) - sizeof(uint32_t);
auto actual_total_size = actual_total_entry_size + actual_total_section_size;
- arch::exception_handling::assert(expected_total_size == actual_total_size,
- "Unexpected elf_symbols_section_header total size");
+ exception_handling::assert(expected_total_size == actual_total_size,
+ "Unexpected elf_symbols_section_header total size");
auto begin = reinterpret_cast<elf_section_header *>(&symbol->end);
auto end = begin + symbol->number_of_sections;
- arch::exception_handling::assert(begin->is_null(), "Missing elf_section_header begin");
+ exception_handling::assert(begin->is_null(), "Missing elf_section_header begin");
std::size_t symbol_table_section_count = 0U;
std::size_t dynamic_section_count = 0U;
@@ -80,8 +79,8 @@ namespace teachos::arch::memory::multiboot
}
}
- arch::exception_handling::assert(symbol_table_section_count == 1U, "Unexpected symbol_table_count value");
- arch::exception_handling::assert(dynamic_section_count <= 1U, "Unexpected dynamic_section_count value");
+ exception_handling::assert(symbol_table_section_count == 1U, "Unexpected symbol_table_count value");
+ exception_handling::assert(dynamic_section_count <= 1U, "Unexpected dynamic_section_count value");
}
} // namespace
diff --git a/arch/x86_64/src/memory/paging/page_entry.cpp b/arch/x86_64/src/memory/paging/page_entry.cpp
index 43c0b71..692f8ae 100644
--- a/arch/x86_64/src/memory/paging/page_entry.cpp
+++ b/arch/x86_64/src/memory/paging/page_entry.cpp
@@ -35,8 +35,8 @@ namespace teachos::arch::memory::paging
auto entry::set_address(allocator::physical_frame frame) -> void
{
- arch::exception_handling::assert((frame.start_address() & ~0x000fffff'fffff000) == 0,
- "Start address is not aligned with Page");
+ exception_handling::assert((frame.start_address() & ~0x000fffff'fffff000) == 0,
+ "Start address is not aligned with Page");
flags = std::bitset<64U>(frame.start_address()) | flags;
}
} // namespace teachos::arch::memory::paging
diff --git a/arch/x86_64/src/memory/paging/page_table.cpp b/arch/x86_64/src/memory/paging/page_table.cpp
index 786ff69..8345161 100644
--- a/arch/x86_64/src/memory/paging/page_table.cpp
+++ b/arch/x86_64/src/memory/paging/page_table.cpp
@@ -23,8 +23,8 @@ namespace teachos::arch::memory::paging
auto page_table::next_table(std::size_t table_index) -> void
{
- arch::exception_handling::assert(current_level != LEVEL1,
- "[Page Table] Attempted to call next_table on level 1 page table");
+ exception_handling::assert(current_level != LEVEL1,
+ "[Page Table] Attempted to call next_table on level 1 page table");
auto address = next_table_address(table_index);
if (address.has_value())
@@ -38,7 +38,7 @@ namespace teachos::arch::memory::paging
{
// C array is not bounds checked, therefore we have to check ourselves, to ensure no out of bounds reads, which
// could be incredibly hard to debug later.
- arch::exception_handling::assert(index < PAGE_TABLE_ENTRY_COUNT, "[Page Table] index out of bounds");
+ exception_handling::assert(index < PAGE_TABLE_ENTRY_COUNT, "[Page Table] index out of bounds");
return current_table->entries[index];
}
diff --git a/arch/x86_64/src/memory/paging/virtual_page.cpp b/arch/x86_64/src/memory/paging/virtual_page.cpp
new file mode 100644
index 0000000..3fb6caf
--- /dev/null
+++ b/arch/x86_64/src/memory/paging/virtual_page.cpp
@@ -0,0 +1,22 @@
+#include "arch/memory/paging/virtual_page.hpp"
+
+#include "arch/exception_handling/assert.hpp"
+#include "arch/memory/allocator/physical_frame.hpp"
+
+namespace teachos::arch::memory::paging
+{
+ virtual_page::virtual_page(std::size_t page_number)
+ : page_number(page_number)
+ {
+ // Nothing to do
+ }
+
+ auto virtual_page::containing_address(std::size_t virtual_address) -> virtual_page
+ {
+ exception_handling::assert(virtual_address < 0x0000800000000000 || virtual_address >= 0xffff800000000000,
+ "[Virtual Page] Attempted to create virtual page from invalid address");
+ return virtual_page{virtual_address / allocator::PAGE_FRAME_SIZE};
+ }
+
+ auto virtual_page::start_address() const -> uint64_t { return page_number * allocator::PAGE_FRAME_SIZE; }
+} // namespace teachos::arch::memory::paging