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/exception_handling/assert.cpp2
-rw-r--r--arch/x86_64/src/kernel/main.cpp8
-rw-r--r--arch/x86_64/src/memory/paging/page_mapper.cpp37
-rw-r--r--arch/x86_64/src/memory/paging/page_table.cpp34
4 files changed, 47 insertions, 34 deletions
diff --git a/arch/x86_64/src/exception_handling/assert.cpp b/arch/x86_64/src/exception_handling/assert.cpp
index b36f52d..b2963de 100644
--- a/arch/x86_64/src/exception_handling/assert.cpp
+++ b/arch/x86_64/src/exception_handling/assert.cpp
@@ -1,5 +1,7 @@
#include "arch/exception_handling/assert.hpp"
+#include "arch/exception_handling/panic.hpp"
+
namespace teachos::arch::exception_handling
{
auto assert(bool condition, char const * message) -> void
diff --git a/arch/x86_64/src/kernel/main.cpp b/arch/x86_64/src/kernel/main.cpp
index db0a9ef..88f6329 100644
--- a/arch/x86_64/src/kernel/main.cpp
+++ b/arch/x86_64/src/kernel/main.cpp
@@ -11,11 +11,9 @@ namespace teachos::arch::kernel
{
auto main() -> void
{
- using namespace video::vga;
-
- text::clear();
- text::cursor(false);
- text::write("TeachOS is starting up...", text::common_attributes::green_on_black);
+ video::vga::text::clear();
+ video::vga::text::cursor(false);
+ video::vga::text::write("TeachOS is starting up...", video::vga::text::common_attributes::green_on_black);
auto memory_information = memory::multiboot::read_multiboot2();
memory::allocator::area_frame_allocator allocator(memory_information);
diff --git a/arch/x86_64/src/memory/paging/page_mapper.cpp b/arch/x86_64/src/memory/paging/page_mapper.cpp
index cedda54..01c39ca 100644
--- a/arch/x86_64/src/memory/paging/page_mapper.cpp
+++ b/arch/x86_64/src/memory/paging/page_mapper.cpp
@@ -7,53 +7,46 @@ namespace teachos::arch::memory::paging
constexpr size_t PAGE_TABLE_LEVEL_4_ADDRESS = 0xfffffffffffff000;
}
- auto create_or_get() -> page_table *
+ auto create_or_get() -> page_table_handle
{
- static bool instantiated = false;
- static page_table * active_page = nullptr;
+ static page_table_handle active_page{reinterpret_cast<page_table *>(PAGE_TABLE_LEVEL_4_ADDRESS),
+ page_table::LEVEL4};
- if (instantiated)
- {
- return active_page;
- }
-
- instantiated = true;
- active_page = reinterpret_cast<page_table *>(PAGE_TABLE_LEVEL_4_ADDRESS);
return active_page;
}
auto translate_page(virtual_page page) -> std::optional<allocator::physical_frame>
{
- page_table * current_page_table = create_or_get();
+ auto current_handle = create_or_get();
for (auto level = page_table::LEVEL4; level != page_table::LEVEL1; level--)
{
- auto next_page_table = current_page_table->next_table(page.get_level_index(level));
+ auto next_handle = current_handle.next_table(page.get_level_index(level));
// If the next table method failed then it is highly likely that it was a huge page and we therefore have to parse
// the table differently. Therefore, we attempt to parse it using the method required by huge pages.
- if (!next_page_table)
+ if (!next_handle)
{
return translate_huge_page(page);
}
- current_page_table = next_page_table.value();
+ current_handle = next_handle.value();
}
auto level1_index = page.get_level_index(page_table::LEVEL1);
- auto level1_frame = current_page_table->operator[](level1_index).calculate_pointed_to_frame();
+ auto level1_frame = current_handle[level1_index].calculate_pointed_to_frame();
return level1_frame;
}
auto translate_huge_page(virtual_page page) -> std::optional<allocator::physical_frame>
{
- page_table * current_page_table = create_or_get();
- auto level3_page_table = current_page_table->next_table(page.get_level_index(page_table::LEVEL4));
+ auto current_handle = create_or_get();
+ auto level3_handle = current_handle.next_table(page.get_level_index(page_table::LEVEL4));
- if (!level3_page_table)
+ if (!level3_handle)
{
return std::nullopt;
}
- auto level3_entry = level3_page_table.value()->operator[](page.get_level_index(page_table::LEVEL3));
+ auto level3_entry = level3_handle.value()[page.get_level_index(page_table::LEVEL3)];
auto level3_frame = level3_entry.calculate_pointed_to_frame();
if (level3_frame && level3_entry.contains_flags(entry::HUGE_PAGE))
{
@@ -65,10 +58,10 @@ namespace teachos::arch::memory::paging
page.get_level_index(page_table::LEVEL1)};
}
- auto level2_page_table = level3_page_table.value()->next_table(page.get_level_index(page_table::LEVEL3));
- if (level2_page_table)
+ auto level2_handle = level3_handle.value().next_table(page.get_level_index(page_table::LEVEL3));
+ if (level2_handle)
{
- auto level2_entry = level2_page_table.value()->operator[](page.get_level_index(page_table::LEVEL2));
+ auto level2_entry = level2_handle.value()[page.get_level_index(page_table::LEVEL2)];
auto level2_frame = level2_entry.calculate_pointed_to_frame();
if (level2_frame && level2_entry.contains_flags(entry::HUGE_PAGE))
{
diff --git a/arch/x86_64/src/memory/paging/page_table.cpp b/arch/x86_64/src/memory/paging/page_table.cpp
index 5daf8bb..907b64f 100644
--- a/arch/x86_64/src/memory/paging/page_table.cpp
+++ b/arch/x86_64/src/memory/paging/page_table.cpp
@@ -14,11 +14,8 @@ namespace teachos::arch::memory::paging
}
}
- auto page_table::next_table(std::size_t table_index) -> std::optional<page_table *>
+ auto page_table::next_table(std::size_t table_index) const -> std::optional<page_table *>
{
- // TODO: Find another way to ensure the current page table is not LEVEL1
- // 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)
{
@@ -27,7 +24,7 @@ namespace teachos::arch::memory::paging
return std::nullopt;
}
- auto page_table::operator[](std::size_t index) -> entry &
+ auto page_table::operator[](std::size_t index) const -> entry
{
// 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.
@@ -35,7 +32,7 @@ namespace teachos::arch::memory::paging
return entries[index];
}
- auto page_table::next_table_address(std::size_t table_index) -> std::optional<std::size_t>
+ auto page_table::next_table_address(std::size_t table_index) const -> std::optional<std::size_t>
{
auto entry = this->operator[](table_index);
@@ -47,11 +44,34 @@ namespace teachos::arch::memory::paging
return std::nullopt;
}
- auto operator--(page_table::level & level, int) -> page_table::level
+ auto operator--(page_table::level level, int) -> page_table::level
{
exception_handling::assert(level != page_table::LEVEL1,
"[Page table] Attemptd to decrement enum to value outside of range");
auto value = static_cast<std::underlying_type<page_table::level>::type>(level);
return static_cast<page_table::level>(--value);
}
+
+ page_table_handle::page_table_handle(page_table * handle, page_table::level handle_level)
+ : handle(handle)
+ , handle_level(handle_level)
+ {
+ exception_handling::assert(handle, "[Page table] Attemptd to pass nullptr as handle to page table handle method");
+ }
+
+ auto page_table_handle::zero_entries() -> void { handle->zero_entries(); }
+
+ auto page_table_handle::next_table(std::size_t table_index) const -> std::optional<page_table_handle>
+ {
+ exception_handling::assert(handle_level != page_table::LEVEL1,
+ "[Page Table] Attempted to call next_table on level 1 page table");
+ auto next_table = handle->next_table(table_index);
+ if (next_table)
+ {
+ return page_table_handle{next_table.value(), handle_level--};
+ }
+ return std::nullopt;
+ }
+
+ auto page_table_handle::operator[](std::size_t index) const -> entry { return handle->operator[](index); }
} // namespace teachos::arch::memory::paging