aboutsummaryrefslogtreecommitdiff
path: root/arch
diff options
context:
space:
mode:
authorMatteo Gmür <matteo.gmuer1@ost.ch>2024-10-16 13:33:23 +0000
committerMatteo Gmür <matteo.gmuer1@ost.ch>2024-10-16 13:33:23 +0000
commit934822e48a7c5a3e65ed74261ce5ab4315595f64 (patch)
treefa9e04075b5924d74ee25f0353ce2492099bdee6 /arch
parentf56004a77314d4b4d68bfaf496fd7c6013ba7a27 (diff)
downloadteachos-934822e48a7c5a3e65ed74261ce5ab4315595f64.tar.xz
teachos-934822e48a7c5a3e65ed74261ce5ab4315595f64.zip
Fix compilation issues with assigning values to page_map_variable address
Diffstat (limited to 'arch')
-rw-r--r--arch/x86_64/include/arch/memory/frame_allocator.hpp27
-rw-r--r--arch/x86_64/include/arch/memory/paging.hpp6
-rw-r--r--arch/x86_64/src/boot/boot.s5
-rw-r--r--arch/x86_64/src/memory/frame_allocator.cpp19
-rw-r--r--arch/x86_64/src/memory/paging.cpp13
5 files changed, 36 insertions, 34 deletions
diff --git a/arch/x86_64/include/arch/memory/frame_allocator.hpp b/arch/x86_64/include/arch/memory/frame_allocator.hpp
index 3d1f826..89f2570 100644
--- a/arch/x86_64/include/arch/memory/frame_allocator.hpp
+++ b/arch/x86_64/include/arch/memory/frame_allocator.hpp
@@ -119,16 +119,7 @@ namespace teachos::arch::memory
* @param area_count Amount of total entries in the memory_areas array.
*/
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)
- : 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();
- }
+ std::size_t multiboot_end, memory_area * memory_areas, uint8_t area_count);
/**
* @brief Allocate memory by finding and returning a free physical_frame.
@@ -171,14 +162,14 @@ namespace teachos::arch::memory
*/
auto choose_next_area() -> void;
- physical_frame next_free_frame{0}; ///< The physical_frame after the last allocated one.
- std::optional<memory_area> current_area{std::nullopt}; ///< The current memory area.
- memory_area_iterator area_begin; ///< Pointer to the first element of all memory areas.
- memory_area_iterator area_end; ///< Pointer to one pas the last element of all memory areas.
- physical_frame const kernel_start; ///< The start address of the kernel code in memory.
- physical_frame const kernel_end; ///< The end address of the kernel code in memory.
- physical_frame const multiboot_start; ///< The start address of the multiboot code in memory.
- physical_frame const multiboot_end; ///< The end address of the multiboot code in memory.
+ physical_frame next_free_frame; ///< The physical_frame after the last allocated one.
+ std::optional<memory_area> current_area; ///< The current memory area.
+ memory_area_iterator area_begin; ///< Pointer to the first element of all memory areas.
+ memory_area_iterator area_end; ///< Pointer to one pas the last element of all memory areas.
+ physical_frame const kernel_start; ///< The start address of the kernel code in memory.
+ physical_frame const kernel_end; ///< The end address of the kernel code in memory.
+ physical_frame const multiboot_start; ///< The start address of the multiboot code in memory.
+ physical_frame const multiboot_end; ///< The end address of the multiboot code in memory.
};
} // namespace teachos::arch::memory
diff --git a/arch/x86_64/include/arch/memory/paging.hpp b/arch/x86_64/include/arch/memory/paging.hpp
index c13c3fe..4092d18 100644
--- a/arch/x86_64/include/arch/memory/paging.hpp
+++ b/arch/x86_64/include/arch/memory/paging.hpp
@@ -140,11 +140,7 @@ namespace teachos::arch::memory
* @param index
* @return The address of the accessed entry
*/
- entry & operator[](std::size_t index)
- {
- arch::exception_handling::assert(index < PAGE_TABLE_ENTRY_COUNT, "[Page Table] index out of bounds");
- return entries[index];
- }
+ entry & operator[](std::size_t index);
private:
entry entries[PAGE_TABLE_ENTRY_COUNT];
diff --git a/arch/x86_64/src/boot/boot.s b/arch/x86_64/src/boot/boot.s
index e3d9c37..2aa30c6 100644
--- a/arch/x86_64/src/boot/boot.s
+++ b/arch/x86_64/src/boot/boot.s
@@ -266,9 +266,8 @@ enable_paging:
/* Map the P4 table recursively */
mov $page_map_level_4, %eax
- or 0b11, %eax
- // TODO: WHY THIS THROW ERROR?
- //mov %eax, [$page_map_level_4 + 511 * 8]
+ or 0b11, %eax /* Write present + writable flags into eax register */
+ mov %eax, (page_map_level_4 + 511 * 8)
/* Enable Physical Address Extension */
mov %cr4, %eax
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