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.cpp12
-rw-r--r--arch/x86_64/src/memory/paging.cpp36
2 files changed, 21 insertions, 27 deletions
diff --git a/arch/x86_64/src/memory/frame_allocator.cpp b/arch/x86_64/src/memory/frame_allocator.cpp
index 3733cc3..01dcc88 100644
--- a/arch/x86_64/src/memory/frame_allocator.cpp
+++ b/arch/x86_64/src/memory/frame_allocator.cpp
@@ -1,7 +1,11 @@
#include "arch/memory/frame_allocator.hpp"
+#include "arch/exception_handling/assert.hpp"
+
namespace teachos::arch::memory
{
+ uint64_t PAGE_SIZE;
+
physical_frame::physical_frame(std::size_t frame_number)
: frame_number(frame_number)
{
@@ -13,6 +17,8 @@ namespace teachos::arch::memory
return physical_frame{address / PAGE_FRAME_SIZE};
}
+ auto physical_frame::start_address() const -> uint64_t { return frame_number * PAGE_SIZE; }
+
memory_area_iterator::memory_area_iterator(memory_area * p)
: ptr(p)
{
@@ -103,10 +109,8 @@ namespace teachos::arch::memory
auto area_frame_allocator::deallocate_frame(physical_frame physical_frame) -> void
{
- // TODO: Fix, simply done because compiler will complain if physical_frame is unused and not compile
- if (physical_frame.frame_number == 3)
- {
- }
+ arch::exception_handling::assert(false && physical_frame.frame_number == 0,
+ "[deallocate_frame] Not implemented Exception");
}
auto area_frame_allocator::begin() -> memory_area_iterator { return area_begin; }
diff --git a/arch/x86_64/src/memory/paging.cpp b/arch/x86_64/src/memory/paging.cpp
index 555357c..90c4199 100644
--- a/arch/x86_64/src/memory/paging.cpp
+++ b/arch/x86_64/src/memory/paging.cpp
@@ -1,34 +1,16 @@
#include "arch/memory/paging.hpp"
+#include "arch/exception_handling/assert.hpp"
+
namespace teachos::arch::memory
{
auto entry::is_unused() const -> bool { return flags == 0U; }
auto entry::set_unused() -> void { flags = 0U; }
- auto entry::present() const -> bool { return is_bit_set(0U); }
-
- auto entry::writable() const -> bool { return is_bit_set(1U); }
-
- auto entry::user_accessible() const -> bool { return is_bit_set(2U); }
-
- auto entry::write_through_caching() const -> bool { return is_bit_set(3U); }
-
- auto entry::disabled_caching() const -> bool { return is_bit_set(4U); }
-
- auto entry::is_accessing() const -> bool { return is_bit_set(5U); }
-
- auto entry::is_diry() const -> bool { return is_bit_set(6U); }
-
- auto entry::is_huge_page() const -> bool { return is_bit_set(7U); }
-
- auto entry::is_global() const -> bool { return is_bit_set(8U); }
-
- auto entry::executing_code_forbidden() const -> bool { return is_bit_set(63U); }
-
auto entry::calculate_pointed_to_frame() const -> std::optional<physical_frame>
{
- if (present())
+ if (contains_flags(1))
{
auto physical_address = calculate_physical_address();
return physical_frame::containing_address(physical_address);
@@ -39,7 +21,7 @@ namespace teachos::arch::memory
auto entry::calculate_physical_address() const -> std::size_t
{
constexpr std::size_t start_bit = 12U;
- constexpr std::size_t end_bit = 51U;
+ constexpr std::size_t end_bit = 52U;
size_t value = 0U;
for (auto i = start_bit; i < end_bit; i++)
@@ -49,5 +31,13 @@ namespace teachos::arch::memory
return value;
}
- auto entry::is_bit_set(uint8_t index) const -> bool { return flags[index] == 1U; }
+ auto entry::set(physical_frame frame) -> void
+ {
+ arch::exception_handling::assert((frame.start_address() & ~0x000fffff'fffff000) == 0,
+ "Start address is not aligned with Page");
+ flags = std::bitset<64U>(frame.start_address()) | flags;
+ }
+
+ auto entry::contains_flags(std::bitset<64U> b) const -> bool { return (flags & b) == b; }
+
} // namespace teachos::arch::memory