From 675f38d6733fb19b4ffc7e9fbddb93acdd1d1e31 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matteo=20Gm=C3=BCr?= Date: Sat, 19 Oct 2024 14:40:25 +0000 Subject: Seperate allocation and paging code into multiple files as well --- .../src/memory/allocator/area_frame_allocator.cpp | 97 ++++++++++++++++++++++ .../x86_64/src/memory/allocator/physical_frame.cpp | 22 +++++ 2 files changed, 119 insertions(+) create mode 100644 arch/x86_64/src/memory/allocator/area_frame_allocator.cpp create mode 100644 arch/x86_64/src/memory/allocator/physical_frame.cpp (limited to 'arch/x86_64/src/memory/allocator') diff --git a/arch/x86_64/src/memory/allocator/area_frame_allocator.cpp b/arch/x86_64/src/memory/allocator/area_frame_allocator.cpp new file mode 100644 index 0000000..9c344d8 --- /dev/null +++ b/arch/x86_64/src/memory/allocator/area_frame_allocator.cpp @@ -0,0 +1,97 @@ +#include "arch/memory/allocator/area_frame_allocator.hpp" + +#include "arch/exception_handling/assert.hpp" + +namespace teachos::arch::memory::allocator +{ + area_frame_allocator::area_frame_allocator(multiboot::memory_information mem_info) + : next_free_frame(0) + , current_area(std::nullopt) + , area_begin(mem_info.memory_areas) + , area_end(mem_info.memory_areas + mem_info.area_count) + , kernel_start(physical_frame::containing_address(mem_info.kernel_start)) + , kernel_end(physical_frame::containing_address(mem_info.kernel_end)) + , multiboot_start(physical_frame::containing_address(mem_info.multiboot_start)) + , multiboot_end(physical_frame::containing_address(mem_info.multiboot_end)) + { + choose_next_area(); + } + + auto area_frame_allocator::choose_next_area() -> void + { + current_area = std::nullopt; + + for (multiboot::memory_area_iterator it = begin(); it != end(); ++it) + { + multiboot::memory_area & area = *it; + + std::size_t address = area.base_address + area.area_length - 1; + if (physical_frame::containing_address(address) >= next_free_frame) + { + // The `next_free_frame` address is smaller than the last address of the current area + if (!current_area || area.base_address < current_area->base_address) + { + current_area = area; + } + } + } + + if (current_area) + { + // Update the `next_free_frame` according to the new memory area + physical_frame start_frame = physical_frame::containing_address(current_area->base_address); + if (next_free_frame < start_frame) + { + next_free_frame = start_frame; + } + } + } + + auto area_frame_allocator::allocate_frame() -> std::optional + { + /* + * Only try to allocate memory if current_area is not null, because + * the current_area is null if there is no more available memory. + */ + if (current_area) + { + physical_frame physical_frame{next_free_frame.frame_number}; + + struct physical_frame current_area_last_frame = { + physical_frame::containing_address(current_area->base_address + current_area->area_length - 1)}; + + if (next_free_frame > current_area_last_frame) + { + // All frames of current area are used, switch to next area + choose_next_area(); + } + else if (physical_frame >= multiboot_start && physical_frame <= kernel_end) + { + // `physical_frame` is used by the kernel or multiboot information structure + next_free_frame = allocator::physical_frame{kernel_end.frame_number + 1}; + } + else + { + // Frame is unused, increment `next_free_frame` and return it + next_free_frame.frame_number += 1; + return physical_frame; + } + + // `physical_frame` was not valid, try it again with the updated `next_free_frame` + return allocate_frame(); + } + + // no free frames left + return std::nullopt; + } + + 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"); + } + + auto area_frame_allocator::begin() -> multiboot::memory_area_iterator { return area_begin; } + + auto area_frame_allocator::end() -> multiboot::memory_area_iterator { return area_end; } +} // namespace teachos::arch::memory::allocator diff --git a/arch/x86_64/src/memory/allocator/physical_frame.cpp b/arch/x86_64/src/memory/allocator/physical_frame.cpp new file mode 100644 index 0000000..03ec193 --- /dev/null +++ b/arch/x86_64/src/memory/allocator/physical_frame.cpp @@ -0,0 +1,22 @@ +#include "arch/memory/allocator/physical_frame.hpp" + +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) + { + // Nothing to do + } + + auto physical_frame::containing_address(std::size_t address) -> physical_frame + { + return physical_frame{address / PAGE_FRAME_SIZE}; + } + + auto physical_frame::start_address() const -> uint64_t { return frame_number * PAGE_FRAME_SIZE; } +} // namespace teachos::arch::memory::allocator -- cgit v1.2.3 From d728052d62470799f73f6d9a2b8baa2b0b357383 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matteo=20Gm=C3=BCr?= Date: Sun, 20 Oct 2024 07:01:53 +0000 Subject: Add helper methods to phyisca frame --- arch/x86_64/src/memory/allocator/area_frame_allocator.cpp | 4 ++-- arch/x86_64/src/memory/allocator/physical_frame.cpp | 5 ----- 2 files changed, 2 insertions(+), 7 deletions(-) (limited to 'arch/x86_64/src/memory/allocator') 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) { -- cgit v1.2.3 From a29e823c6ead21fa7c8f6445411d52f57c4518fb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matteo=20Gm=C3=BCr?= Date: Sun, 27 Oct 2024 09:21:25 +0000 Subject: Attempt to start using C++20 algorithm calls. --- .../src/memory/allocator/area_frame_allocator.cpp | 24 ++++++++++++++-------- 1 file changed, 15 insertions(+), 9 deletions(-) (limited to 'arch/x86_64/src/memory/allocator') 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 c2cafce..c3f77e1 100644 --- a/arch/x86_64/src/memory/allocator/area_frame_allocator.cpp +++ b/arch/x86_64/src/memory/allocator/area_frame_allocator.cpp @@ -2,13 +2,16 @@ #include "arch/exception_handling/assert.hpp" +#include +#include +#include + namespace teachos::arch::memory::allocator { area_frame_allocator::area_frame_allocator(multiboot::memory_information mem_info) : next_free_frame(0) , current_area(std::nullopt) - , area_begin(mem_info.memory_areas) - , area_end(mem_info.memory_areas + mem_info.area_count) + , memory_areas(mem_info.memory_areas, mem_info.area_count) , kernel_start(physical_frame::containing_address(mem_info.kernel_start)) , kernel_end(physical_frame::containing_address(mem_info.kernel_end)) , multiboot_start(physical_frame::containing_address(mem_info.multiboot_start)) @@ -21,10 +24,17 @@ namespace teachos::arch::memory::allocator { current_area = std::nullopt; - for (multiboot::memory_area_iterator it = begin(); it != end(); ++it) - { - multiboot::memory_area & area = *it; + /**auto filtered_areas = memory_areas | std::views::filter([this](multiboot::memory_area area) { + auto address = area.base_address + area.area_length - 1; + return physical_frame::containing_address(address) >= next_free_frame; + });**/ + + std::ranges::min_element(memory_areas, [](multiboot::memory_area a, multiboot::memory_area b) { + return a.base_address < b.base_address; + }); + for (auto area : memory_areas) + { std::size_t address = area.base_address + area.area_length - 1; if (physical_frame::containing_address(address) >= next_free_frame) { @@ -90,8 +100,4 @@ namespace teachos::arch::memory::allocator 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; } - - auto area_frame_allocator::end() -> multiboot::memory_area_iterator { return area_end; } } // namespace teachos::arch::memory::allocator -- cgit v1.2.3 From 3fb2780f665eb3514ef07d2d4a83820653e35b52 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matteo=20Gm=C3=BCr?= Date: Sun, 27 Oct 2024 11:20:46 +0000 Subject: Use container and C++20 range algorithms for allocator. --- .../src/memory/allocator/area_frame_allocator.cpp | 86 ++++++++++------------ 1 file changed, 38 insertions(+), 48 deletions(-) (limited to 'arch/x86_64/src/memory/allocator') 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 c3f77e1..d91b7f4 100644 --- a/arch/x86_64/src/memory/allocator/area_frame_allocator.cpp +++ b/arch/x86_64/src/memory/allocator/area_frame_allocator.cpp @@ -23,33 +23,21 @@ namespace teachos::arch::memory::allocator auto area_frame_allocator::choose_next_area() -> void { current_area = std::nullopt; + auto next_area_with_free_frames = memory_areas | std::views::filter([this](multiboot::memory_area const & area) { + auto address = area.base_address + area.area_length - 1; + return physical_frame::containing_address(address) >= next_free_frame; + }); - /**auto filtered_areas = memory_areas | std::views::filter([this](multiboot::memory_area area) { - auto address = area.base_address + area.area_length - 1; - return physical_frame::containing_address(address) >= next_free_frame; - });**/ + auto lowest_area_with_free_frames = + std::ranges::min_element(next_area_with_free_frames, [](multiboot::memory_area a, multiboot::memory_area b) { + return a.base_address < b.base_address; + }); - std::ranges::min_element(memory_areas, [](multiboot::memory_area a, multiboot::memory_area b) { - return a.base_address < b.base_address; - }); - - for (auto area : memory_areas) - { - std::size_t address = area.base_address + area.area_length - 1; - if (physical_frame::containing_address(address) >= next_free_frame) - { - // The `next_free_frame` address is smaller than the last address of the current area - if (!current_area || area.base_address < current_area->base_address) - { - current_area = area; - } - } - } - - if (current_area) + if (lowest_area_with_free_frames != next_area_with_free_frames.end()) { + current_area = *lowest_area_with_free_frames; // Update the `next_free_frame` according to the new memory area - physical_frame start_frame = physical_frame::containing_address(current_area->base_address); + auto start_frame = physical_frame::containing_address(current_area.value().base_address); if (next_free_frame < start_frame) { next_free_frame = start_frame; @@ -63,36 +51,38 @@ namespace teachos::arch::memory::allocator * Only try to allocate memory if current_area is not null, because * the current_area is null if there is no more available memory. */ - if (current_area) + if (!current_area) { - physical_frame physical_frame{next_free_frame.frame_number}; + return std::nullopt; + } - struct physical_frame current_area_last_frame = { - physical_frame::containing_address(current_area->base_address + current_area->area_length - 1)}; + auto address = current_area.value().base_address + current_area.value().area_length - 1; + physical_frame current_area_last_frame = physical_frame::containing_address(address); - if (next_free_frame > current_area_last_frame) - { - // All frames of current area are used, switch to next area - choose_next_area(); - } - else if (physical_frame >= multiboot_start && physical_frame <= kernel_end) - { - // `physical_frame` is used by the kernel or multiboot information structure - next_free_frame = allocator::physical_frame{kernel_end.frame_number + 1}; - } - else - { - // Frame is unused, increment `next_free_frame` and return it - next_free_frame.frame_number += 1; - return physical_frame; - } - - // `physical_frame` was not valid, try it again with the updated `next_free_frame` - return allocate_frame(); + if (next_free_frame > current_area_last_frame) + { + // All frames of current area are used, switch to next area. + choose_next_area(); + } + else if (next_free_frame >= kernel_start && next_free_frame <= kernel_end) + { + // `physical_frame` is used by the kernel or multiboot information structure. + next_free_frame = allocator::physical_frame{kernel_end.frame_number + 1}; + } + else if (next_free_frame >= multiboot_start && next_free_frame <= multiboot_end) + { + // `physical_frame` is used by the kernel or multiboot information structure. + next_free_frame = allocator::physical_frame{multiboot_end.frame_number + 1}; + } + else + { + // Frame is unused, increment `next_free_frame` and return it. + next_free_frame.frame_number += 1; + return next_free_frame; } - // no free frames left - return std::nullopt; + // `physical_frame` was not valid, try it again with the updated `next_free_frame`. + return allocate_frame(); } auto area_frame_allocator::deallocate_frame(physical_frame physical_frame) -> void -- cgit v1.2.3 From 1518177efac38961a36db0bc40152d00c38e6281 Mon Sep 17 00:00:00 2001 From: Fabian Imhof Date: Sun, 27 Oct 2024 13:27:33 +0000 Subject: add correct optional handling --- .../src/memory/allocator/area_frame_allocator.cpp | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) (limited to 'arch/x86_64/src/memory/allocator') 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 c2cafce..05b828c 100644 --- a/arch/x86_64/src/memory/allocator/area_frame_allocator.cpp +++ b/arch/x86_64/src/memory/allocator/area_frame_allocator.cpp @@ -29,14 +29,14 @@ namespace teachos::arch::memory::allocator if (physical_frame::containing_address(address) >= next_free_frame) { // The `next_free_frame` address is smaller than the last address of the current area - if (!current_area || area.base_address < current_area->base_address) + if (!current_area.has_value() || area.base_address < current_area.value().base_address) { - current_area = area; + current_area.emplace(area); } } } - if (current_area) + if (current_area.has_value()) { // Update the `next_free_frame` according to the new memory area physical_frame start_frame = physical_frame::containing_address(current_area->base_address); @@ -53,7 +53,7 @@ namespace teachos::arch::memory::allocator * Only try to allocate memory if current_area is not null, because * the current_area is null if there is no more available memory. */ - if (current_area) + if (current_area.has_value()) { physical_frame physical_frame{next_free_frame.frame_number}; @@ -65,11 +65,16 @@ namespace teachos::arch::memory::allocator // All frames of current area are used, switch to next area choose_next_area(); } - else if (physical_frame >= multiboot_start && physical_frame <= kernel_end) + else if (physical_frame >= kernel_start && physical_frame <= kernel_end) { - // `physical_frame` is used by the kernel or multiboot information structure + // `physical_frame` is used by the kernel next_free_frame = allocator::physical_frame{kernel_end.frame_number + 1}; } + else if (physical_frame >= multiboot_start && physical_frame <= multiboot_end) + { + // `physical_frame` is used by the multiboot information structure + next_free_frame = allocator::physical_frame{multiboot_end.frame_number + 1}; + } else { // Frame is unused, increment `next_free_frame` and return it -- cgit v1.2.3 From acbd91c9898808a928af0b1bdd9d5058e8a91f62 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matteo=20Gm=C3=BCr?= Date: Sun, 27 Oct 2024 14:55:52 +0000 Subject: Add typedef for virtual / physical addresses --- arch/x86_64/src/memory/allocator/physical_frame.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'arch/x86_64/src/memory/allocator') diff --git a/arch/x86_64/src/memory/allocator/physical_frame.cpp b/arch/x86_64/src/memory/allocator/physical_frame.cpp index 03bd965..b05254b 100644 --- a/arch/x86_64/src/memory/allocator/physical_frame.cpp +++ b/arch/x86_64/src/memory/allocator/physical_frame.cpp @@ -8,7 +8,7 @@ namespace teachos::arch::memory::allocator // Nothing to do } - auto physical_frame::containing_address(std::size_t address) -> physical_frame + auto physical_frame::containing_address(physical_address address) -> physical_frame { return physical_frame{address / PAGE_FRAME_SIZE}; } -- cgit v1.2.3 From 04b0285d8329e45cea426aa1a8e69203685a4467 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matteo=20Gm=C3=BCr?= Date: Mon, 28 Oct 2024 10:15:18 +0000 Subject: Move iterator and container into generic template classes. Use algorithms instead of raw pointer for loops --- arch/x86_64/src/memory/allocator/area_frame_allocator.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'arch/x86_64/src/memory/allocator') 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 6ed4f28..e03c66a 100644 --- a/arch/x86_64/src/memory/allocator/area_frame_allocator.cpp +++ b/arch/x86_64/src/memory/allocator/area_frame_allocator.cpp @@ -9,9 +9,9 @@ namespace teachos::arch::memory::allocator { area_frame_allocator::area_frame_allocator(multiboot::memory_information mem_info) - : next_free_frame(0) + : next_free_frame(0U) , current_area(std::nullopt) - , memory_areas(mem_info.memory_areas, mem_info.area_count) + , memory_areas(mem_info.begin_area, mem_info.end_area) , kernel_start(physical_frame::containing_address(mem_info.kernel_start)) , kernel_end(physical_frame::containing_address(mem_info.kernel_end)) , multiboot_start(physical_frame::containing_address(mem_info.multiboot_start)) -- cgit v1.2.3 From e5925df93411429340d2887594004aaa690d2ef5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matteo=20Gm=C3=BCr?= Date: Mon, 28 Oct 2024 13:32:09 +0000 Subject: Adjust constant and make all possible variables const --- arch/x86_64/src/memory/allocator/area_frame_allocator.cpp | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) (limited to 'arch/x86_64/src/memory/allocator') 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 e03c66a..6ec3e95 100644 --- a/arch/x86_64/src/memory/allocator/area_frame_allocator.cpp +++ b/arch/x86_64/src/memory/allocator/area_frame_allocator.cpp @@ -28,7 +28,7 @@ namespace teachos::arch::memory::allocator return physical_frame::containing_address(address) >= next_free_frame; }); - auto lowest_area_with_free_frames = + auto const lowest_area_with_free_frames = std::ranges::min_element(next_area_with_free_frames, [](multiboot::memory_area a, multiboot::memory_area b) { return a.base_address < b.base_address; }); @@ -37,7 +37,7 @@ namespace teachos::arch::memory::allocator { current_area = *lowest_area_with_free_frames; // Update the `next_free_frame` according to the new memory area - auto start_frame = physical_frame::containing_address(current_area.value().base_address); + auto const start_frame = physical_frame::containing_address(current_area.value().base_address); if (next_free_frame < start_frame) { next_free_frame = start_frame; @@ -47,16 +47,14 @@ namespace teachos::arch::memory::allocator auto area_frame_allocator::allocate_frame() -> std::optional { - /* - * Only try to allocate memory if current_area is not null, because - * the current_area is null if there is no more available memory. - */ + // Only try to allocate memory if current_area is not null, because + // the current_area is null if there is no more available memory. if (!current_area.has_value()) { return std::nullopt; } - auto address = current_area.value().base_address + current_area.value().area_length - 1; + auto const address = current_area.value().base_address + current_area.value().area_length - 1; physical_frame current_area_last_frame = physical_frame::containing_address(address); if (next_free_frame > current_area_last_frame) -- cgit v1.2.3 From aa981cad951c4aa2a5e2f7a7f8f1b7b9a0ff4bcd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matteo=20Gm=C3=BCr?= Date: Mon, 28 Oct 2024 14:41:31 +0000 Subject: Fix lost updates, because of writing into copies instead of references --- arch/x86_64/src/memory/allocator/area_frame_allocator.cpp | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) (limited to 'arch/x86_64/src/memory/allocator') 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 6ec3e95..fecc6cd 100644 --- a/arch/x86_64/src/memory/allocator/area_frame_allocator.cpp +++ b/arch/x86_64/src/memory/allocator/area_frame_allocator.cpp @@ -85,7 +85,11 @@ namespace teachos::arch::memory::allocator auto area_frame_allocator::deallocate_frame(physical_frame physical_frame) -> void { - exception_handling::assert(false && physical_frame.frame_number == 0, - "[deallocate_frame] Not implemented Exception"); + // TODO: Implement deallocation to make unmap actually work. + if (physical_frame.frame_number == 0) + { + } + /*exception_handling::assert(false && physical_frame.frame_number == 0, + "[deallocate_frame] Not implemented Exception");*/ } } // namespace teachos::arch::memory::allocator -- cgit v1.2.3 From f9f047f519d0100c40b914d3ce777ac2f8430b38 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matteo=20Gm=C3=BCr?= Date: Mon, 28 Oct 2024 15:18:31 +0000 Subject: Add is empty check method for page table --- arch/x86_64/src/memory/allocator/area_frame_allocator.cpp | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) (limited to 'arch/x86_64/src/memory/allocator') 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 fecc6cd..e79cd8b 100644 --- a/arch/x86_64/src/memory/allocator/area_frame_allocator.cpp +++ b/arch/x86_64/src/memory/allocator/area_frame_allocator.cpp @@ -85,11 +85,8 @@ namespace teachos::arch::memory::allocator auto area_frame_allocator::deallocate_frame(physical_frame physical_frame) -> void { - // TODO: Implement deallocation to make unmap actually work. - if (physical_frame.frame_number == 0) - { - } - /*exception_handling::assert(false && physical_frame.frame_number == 0, - "[deallocate_frame] Not implemented Exception");*/ + // TODO: Fix create acutal deallocation of frames if it is even possible. Can the area frame allocator even + // deallocate in the first place? + next_free_frame = physical_frame; } } // namespace teachos::arch::memory::allocator -- cgit v1.2.3 From 0d16592c8dce876d8e621c73dea41c33339f3173 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matteo=20Gm=C3=BCr?= Date: Tue, 29 Oct 2024 06:55:36 +0000 Subject: Use more virtual and physical address typedef where useful --- arch/x86_64/src/memory/allocator/physical_frame.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'arch/x86_64/src/memory/allocator') diff --git a/arch/x86_64/src/memory/allocator/physical_frame.cpp b/arch/x86_64/src/memory/allocator/physical_frame.cpp index b05254b..bef9322 100644 --- a/arch/x86_64/src/memory/allocator/physical_frame.cpp +++ b/arch/x86_64/src/memory/allocator/physical_frame.cpp @@ -13,5 +13,5 @@ namespace teachos::arch::memory::allocator return physical_frame{address / PAGE_FRAME_SIZE}; } - auto physical_frame::start_address() const -> uint64_t { return frame_number * PAGE_FRAME_SIZE; } + auto physical_frame::start_address() const -> physical_address { return frame_number * PAGE_FRAME_SIZE; } } // namespace teachos::arch::memory::allocator -- cgit v1.2.3 From 5334a63e7fc3959536f4f443c86f8913f7cb2451 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matteo=20Gm=C3=BCr?= Date: Tue, 29 Oct 2024 08:05:22 +0000 Subject: Unmap all empty page tables in unmap function. --- arch/x86_64/src/memory/allocator/area_frame_allocator.cpp | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) (limited to 'arch/x86_64/src/memory/allocator') 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 e79cd8b..1e87147 100644 --- a/arch/x86_64/src/memory/allocator/area_frame_allocator.cpp +++ b/arch/x86_64/src/memory/allocator/area_frame_allocator.cpp @@ -83,10 +83,5 @@ namespace teachos::arch::memory::allocator return allocate_frame(); } - auto area_frame_allocator::deallocate_frame(physical_frame physical_frame) -> void - { - // TODO: Fix create acutal deallocation of frames if it is even possible. Can the area frame allocator even - // deallocate in the first place? - next_free_frame = physical_frame; - } + auto area_frame_allocator::deallocate_frame(physical_frame physical_frame) -> void { (void)physical_frame; } } // namespace teachos::arch::memory::allocator -- cgit v1.2.3 From dfb0ea2fd7525dd12addf295aef4d642e93ea22a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matteo=20Gm=C3=BCr?= Date: Tue, 29 Oct 2024 09:31:36 +0000 Subject: Create tiny frame allocator which holds only 3 frames --- .../src/memory/allocator/tiny_frame_allocator.cpp | 34 ++++++++++++++++++++++ 1 file changed, 34 insertions(+) create mode 100644 arch/x86_64/src/memory/allocator/tiny_frame_allocator.cpp (limited to 'arch/x86_64/src/memory/allocator') diff --git a/arch/x86_64/src/memory/allocator/tiny_frame_allocator.cpp b/arch/x86_64/src/memory/allocator/tiny_frame_allocator.cpp new file mode 100644 index 0000000..d07398a --- /dev/null +++ b/arch/x86_64/src/memory/allocator/tiny_frame_allocator.cpp @@ -0,0 +1,34 @@ +#include "arch/memory/allocator/tiny_frame_allocator.hpp" + +#include "arch/exception_handling/panic.hpp" + +namespace teachos::arch::memory::allocator +{ + auto tiny_frame_allocator::allocate_frame() -> std::optional + { + for (auto & frame_option : frames) + { + if (frame_option.has_value()) + { + auto value = frame_option; + frame_option = std::nullopt; + return value; + } + } + return std::nullopt; + } + + auto tiny_frame_allocator::deallocate_frame(physical_frame physical_frame) -> void + { + for (auto & frame_option : frames) + { + if (!frame_option.has_value()) + { + frame_option = physical_frame; + return; + } + } + exception_handling::panic( + "[Tiny Frame Allocator] Attempted to deallocate more than the 3 frames, that can be held"); + } +} // namespace teachos::arch::memory::allocator -- cgit v1.2.3 From 5ffe7d69545bf098efdd70f105a5df83304b211a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matteo=20Gm=C3=BCr?= Date: Sat, 2 Nov 2024 11:49:38 +0000 Subject: Add physical frame iterator and continue implementing kernel mapping. --- .../src/memory/allocator/area_frame_allocator.cpp | 2 +- .../x86_64/src/memory/allocator/physical_frame.cpp | 123 +++++++++++++++++++++ 2 files changed, 124 insertions(+), 1 deletion(-) (limited to 'arch/x86_64/src/memory/allocator') 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 1e87147..5d56a2a 100644 --- a/arch/x86_64/src/memory/allocator/area_frame_allocator.cpp +++ b/arch/x86_64/src/memory/allocator/area_frame_allocator.cpp @@ -8,7 +8,7 @@ namespace teachos::arch::memory::allocator { - area_frame_allocator::area_frame_allocator(multiboot::memory_information mem_info) + area_frame_allocator::area_frame_allocator(multiboot::memory_information const & mem_info) : next_free_frame(0U) , current_area(std::nullopt) , memory_areas(mem_info.begin_area, mem_info.end_area) diff --git a/arch/x86_64/src/memory/allocator/physical_frame.cpp b/arch/x86_64/src/memory/allocator/physical_frame.cpp index bef9322..9307602 100644 --- a/arch/x86_64/src/memory/allocator/physical_frame.cpp +++ b/arch/x86_64/src/memory/allocator/physical_frame.cpp @@ -14,4 +14,127 @@ namespace teachos::arch::memory::allocator } auto physical_frame::start_address() const -> physical_address { return frame_number * PAGE_FRAME_SIZE; } + + /** + * @brief Constructor. + * + * @param value Underlying value the iterator should point too + */ + physical_frame_iterator::physical_frame_iterator(physical_frame_iterator::value_type value) + : value(value) + { + // Nothing to do + } + + /** + * @brief Dereferences the initally given pointer to its value. + * + * @return Reference to the value. + */ + auto physical_frame_iterator::operator*() -> physical_frame_iterator::value_type & { return value; } + + /** + * @brief Get underlying value, which is the intially passed pointer. + * + * @return Underlying value passed intially. + */ + auto physical_frame_iterator::operator->() -> physical_frame_iterator::value_type * { return &value; } + + /** + * @brief Post increment operator. Returns a copy of the value. + * + * @return Copy of the incremented underlying address. + */ + auto physical_frame_iterator::operator++(int) -> physical_frame_iterator + { + physical_frame_iterator const old_value = *this; + ++value.frame_number; + return old_value; + } + + /** + * @brief Pre increment operator. Returns a reference to the changed value. + * + * @return Reference to the incremented underlying address. + */ + auto physical_frame_iterator::operator++() -> physical_frame_iterator & + { + ++value.frame_number; + return *this; + } + + /** + * @brief Addition assignment operator. Returns a reference to the changed value. + * + * @param operand Value we want to add to the underlying address. + * @return Reference to the changed underlying address. + */ + auto + physical_frame_iterator::operator+=(physical_frame_iterator::difference_type operand) -> physical_frame_iterator & + { + value.frame_number += operand; + return *this; + } + + /** + * @brief Subtraction assignment operator. Returns a reference to the changed value. + * + * @param operand Value we want to subtract from the underlying address. + * @return Reference to the changed underlying address. + */ + auto + physical_frame_iterator::operator-=(physical_frame_iterator::difference_type operand) -> physical_frame_iterator & + { + value.frame_number -= operand; + return *this; + } + + /** + * @brief Addition operator. Returns the changed value. + * + * @param operand Value we want to add to a copy of the underlying address. + * @return Copy of underlying address incremented by the given value. + */ + auto + physical_frame_iterator::operator+(physical_frame_iterator::difference_type operand) const -> physical_frame_iterator + { + return physical_frame_iterator{physical_frame_iterator::value_type{value.frame_number + operand}}; + } + + /** + * @brief Subtraction operator. Returns the changed value. + * + * @param operand Value we want to subtrcat from a copy of the underlying address. + * @return Copy of underlying address decremented by the given value. + */ + auto + physical_frame_iterator::operator-(physical_frame_iterator::difference_type operand) const -> physical_frame_iterator + { + return physical_frame_iterator{physical_frame_iterator::value_type{value.frame_number - operand}}; + } + + /** + * @brief Subtraction operator. Returns the size difference between two iterators. + * + * @param other Other iterator we want to substract the underlying address with ours. + * @return Size difference between the underlying address of this instance and the given iterator. + */ + auto physical_frame_iterator::operator-(const physical_frame_iterator & other) const + -> physical_frame_iterator::difference_type + { + return value.frame_number - other.value.frame_number; + } + + /** + * @brief Index operator overload. Returns a reference to the value at the given index. Simply returns the + * dereferenced underlying pointer incremented by the given index. + * + * @param index Index we want to access and get the value from. + * @return Reference to the value at the given index. + */ + auto physical_frame_iterator::operator[](physical_frame_iterator::difference_type index) const + -> physical_frame_iterator::value_type + { + return physical_frame_iterator::value_type{value.frame_number + index}; + } } // namespace teachos::arch::memory::allocator -- cgit v1.2.3 From 5ade8e0d5f190f2e439f81232b38b90c49c0cd1e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matteo=20Gm=C3=BCr?= Date: Sat, 2 Nov 2024 12:38:22 +0000 Subject: Add comments and improve multiboot information struct usability. --- arch/x86_64/src/memory/allocator/area_frame_allocator.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'arch/x86_64/src/memory/allocator') 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 5d56a2a..da4a919 100644 --- a/arch/x86_64/src/memory/allocator/area_frame_allocator.cpp +++ b/arch/x86_64/src/memory/allocator/area_frame_allocator.cpp @@ -11,7 +11,7 @@ namespace teachos::arch::memory::allocator area_frame_allocator::area_frame_allocator(multiboot::memory_information const & mem_info) : next_free_frame(0U) , current_area(std::nullopt) - , memory_areas(mem_info.begin_area, mem_info.end_area) + , memory_areas(mem_info.areas) , kernel_start(physical_frame::containing_address(mem_info.kernel_start)) , kernel_end(physical_frame::containing_address(mem_info.kernel_end)) , multiboot_start(physical_frame::containing_address(mem_info.multiboot_start)) -- cgit v1.2.3 From 4d76f412b071a05f0aae1d1307f2b58cb2778569 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matteo=20Gm=C3=BCr?= Date: Sat, 2 Nov 2024 14:08:55 +0000 Subject: Attempt to fix crashes --- arch/x86_64/src/memory/allocator/tiny_frame_allocator.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'arch/x86_64/src/memory/allocator') diff --git a/arch/x86_64/src/memory/allocator/tiny_frame_allocator.cpp b/arch/x86_64/src/memory/allocator/tiny_frame_allocator.cpp index d07398a..b9fd2c8 100644 --- a/arch/x86_64/src/memory/allocator/tiny_frame_allocator.cpp +++ b/arch/x86_64/src/memory/allocator/tiny_frame_allocator.cpp @@ -11,7 +11,7 @@ namespace teachos::arch::memory::allocator if (frame_option.has_value()) { auto value = frame_option; - frame_option = std::nullopt; + frame_option.reset(); return value; } } @@ -24,7 +24,7 @@ namespace teachos::arch::memory::allocator { if (!frame_option.has_value()) { - frame_option = physical_frame; + frame_option.emplace(physical_frame); return; } } -- cgit v1.2.3 From 9292814545ab5df5aa69d4f75a6d9230f3e03f5b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matteo=20Gm=C3=BCr?= Date: Sun, 3 Nov 2024 11:03:34 +0000 Subject: Move possible implementation into cpp --- .../x86_64/src/memory/allocator/tiny_frame_allocator.cpp | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) (limited to 'arch/x86_64/src/memory/allocator') diff --git a/arch/x86_64/src/memory/allocator/tiny_frame_allocator.cpp b/arch/x86_64/src/memory/allocator/tiny_frame_allocator.cpp index b9fd2c8..d37864e 100644 --- a/arch/x86_64/src/memory/allocator/tiny_frame_allocator.cpp +++ b/arch/x86_64/src/memory/allocator/tiny_frame_allocator.cpp @@ -4,6 +4,22 @@ namespace teachos::arch::memory::allocator { + tiny_frame_allocator::tiny_frame_allocator(area_frame_allocator & allocator) + : frames{} + { + // Has to be done this way, because constructing the constructor with the data from allocator.allocate_frames(), + // does not work because it would set the value correctly but because we pass it as an std::optional it would not + // set the engaged flag. Meaning the has_value() method would still return false. + for (auto & frame : frames) + { + auto allocated = allocator.allocate_frame(); + if (allocated.has_value()) + { + frame.emplace(allocated.value()); + } + } + } + auto tiny_frame_allocator::allocate_frame() -> std::optional { for (auto & frame_option : frames) -- cgit v1.2.3 From 380bc85d1a4fdbef102132c726ef2ac7ac6355da Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matteo=20Gm=C3=BCr?= Date: Sun, 3 Nov 2024 12:20:21 +0000 Subject: Make constructor constexpr for basic page and frame types --- arch/x86_64/src/memory/allocator/physical_frame.cpp | 6 ------ 1 file changed, 6 deletions(-) (limited to 'arch/x86_64/src/memory/allocator') diff --git a/arch/x86_64/src/memory/allocator/physical_frame.cpp b/arch/x86_64/src/memory/allocator/physical_frame.cpp index 9307602..227745a 100644 --- a/arch/x86_64/src/memory/allocator/physical_frame.cpp +++ b/arch/x86_64/src/memory/allocator/physical_frame.cpp @@ -2,12 +2,6 @@ namespace teachos::arch::memory::allocator { - physical_frame::physical_frame(std::size_t frame_number) - : frame_number(frame_number) - { - // Nothing to do - } - auto physical_frame::containing_address(physical_address address) -> physical_frame { return physical_frame{address / PAGE_FRAME_SIZE}; -- cgit v1.2.3 From 162bea11c7a4f1854cde53920b4c14b4eadf539d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matteo=20Gm=C3=BCr?= Date: Mon, 4 Nov 2024 12:13:44 +0000 Subject: WIP attempt to fix crashes --- .../src/memory/allocator/area_frame_allocator.cpp | 12 +-- .../x86_64/src/memory/allocator/physical_frame.cpp | 113 +++------------------ 2 files changed, 20 insertions(+), 105 deletions(-) (limited to 'arch/x86_64/src/memory/allocator') 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 da4a919..42aff68 100644 --- a/arch/x86_64/src/memory/allocator/area_frame_allocator.cpp +++ b/arch/x86_64/src/memory/allocator/area_frame_allocator.cpp @@ -23,19 +23,17 @@ namespace teachos::arch::memory::allocator auto area_frame_allocator::choose_next_area() -> void { current_area = std::nullopt; - auto next_area_with_free_frames = memory_areas | std::views::filter([this](multiboot::memory_area const & area) { - auto address = area.base_address + area.area_length - 1; + auto next_area_with_free_frames = memory_areas | std::views::filter([this](auto const & area) { + auto address = area->base_address + area->area_length - 1; return physical_frame::containing_address(address) >= next_free_frame; }); - auto const lowest_area_with_free_frames = - std::ranges::min_element(next_area_with_free_frames, [](multiboot::memory_area a, multiboot::memory_area b) { - return a.base_address < b.base_address; - }); + auto const lowest_area_with_free_frames = std::ranges::min_element( + next_area_with_free_frames, [](auto const & a, auto const & b) { return a->base_address < b->base_address; }); if (lowest_area_with_free_frames != next_area_with_free_frames.end()) { - current_area = *lowest_area_with_free_frames; + current_area = **lowest_area_with_free_frames; // Update the `next_free_frame` according to the new memory area auto const start_frame = physical_frame::containing_address(current_area.value().base_address); if (next_free_frame < start_frame) diff --git a/arch/x86_64/src/memory/allocator/physical_frame.cpp b/arch/x86_64/src/memory/allocator/physical_frame.cpp index 227745a..63d84ec 100644 --- a/arch/x86_64/src/memory/allocator/physical_frame.cpp +++ b/arch/x86_64/src/memory/allocator/physical_frame.cpp @@ -9,126 +9,43 @@ namespace teachos::arch::memory::allocator auto physical_frame::start_address() const -> physical_address { return frame_number * PAGE_FRAME_SIZE; } - /** - * @brief Constructor. - * - * @param value Underlying value the iterator should point too - */ - physical_frame_iterator::physical_frame_iterator(physical_frame_iterator::value_type value) - : value(value) + auto physical_frame::operator++(int) -> physical_frame { - // Nothing to do - } - - /** - * @brief Dereferences the initally given pointer to its value. - * - * @return Reference to the value. - */ - auto physical_frame_iterator::operator*() -> physical_frame_iterator::value_type & { return value; } - - /** - * @brief Get underlying value, which is the intially passed pointer. - * - * @return Underlying value passed intially. - */ - auto physical_frame_iterator::operator->() -> physical_frame_iterator::value_type * { return &value; } - - /** - * @brief Post increment operator. Returns a copy of the value. - * - * @return Copy of the incremented underlying address. - */ - auto physical_frame_iterator::operator++(int) -> physical_frame_iterator - { - physical_frame_iterator const old_value = *this; - ++value.frame_number; + physical_frame const old_value = *this; + ++frame_number; return old_value; } - /** - * @brief Pre increment operator. Returns a reference to the changed value. - * - * @return Reference to the incremented underlying address. - */ - auto physical_frame_iterator::operator++() -> physical_frame_iterator & + auto physical_frame::operator++() -> physical_frame & { - ++value.frame_number; + ++frame_number; return *this; } - /** - * @brief Addition assignment operator. Returns a reference to the changed value. - * - * @param operand Value we want to add to the underlying address. - * @return Reference to the changed underlying address. - */ - auto - physical_frame_iterator::operator+=(physical_frame_iterator::difference_type operand) -> physical_frame_iterator & + auto physical_frame::operator+=(std::size_t operand) -> physical_frame & { - value.frame_number += operand; + frame_number += operand; return *this; } - /** - * @brief Subtraction assignment operator. Returns a reference to the changed value. - * - * @param operand Value we want to subtract from the underlying address. - * @return Reference to the changed underlying address. - */ - auto - physical_frame_iterator::operator-=(physical_frame_iterator::difference_type operand) -> physical_frame_iterator & + auto physical_frame::operator-=(std::size_t operand) -> physical_frame & { - value.frame_number -= operand; + frame_number -= operand; return *this; } - /** - * @brief Addition operator. Returns the changed value. - * - * @param operand Value we want to add to a copy of the underlying address. - * @return Copy of underlying address incremented by the given value. - */ - auto - physical_frame_iterator::operator+(physical_frame_iterator::difference_type operand) const -> physical_frame_iterator - { - return physical_frame_iterator{physical_frame_iterator::value_type{value.frame_number + operand}}; - } - - /** - * @brief Subtraction operator. Returns the changed value. - * - * @param operand Value we want to subtrcat from a copy of the underlying address. - * @return Copy of underlying address decremented by the given value. - */ - auto - physical_frame_iterator::operator-(physical_frame_iterator::difference_type operand) const -> physical_frame_iterator + auto physical_frame::operator+(std::size_t operand) const -> physical_frame { - return physical_frame_iterator{physical_frame_iterator::value_type{value.frame_number - operand}}; + return physical_frame{frame_number + operand}; } - /** - * @brief Subtraction operator. Returns the size difference between two iterators. - * - * @param other Other iterator we want to substract the underlying address with ours. - * @return Size difference between the underlying address of this instance and the given iterator. - */ - auto physical_frame_iterator::operator-(const physical_frame_iterator & other) const - -> physical_frame_iterator::difference_type + auto physical_frame::operator-(std::size_t operand) const -> physical_frame { - return value.frame_number - other.value.frame_number; + return physical_frame{frame_number - operand}; } - /** - * @brief Index operator overload. Returns a reference to the value at the given index. Simply returns the - * dereferenced underlying pointer incremented by the given index. - * - * @param index Index we want to access and get the value from. - * @return Reference to the value at the given index. - */ - auto physical_frame_iterator::operator[](physical_frame_iterator::difference_type index) const - -> physical_frame_iterator::value_type + auto physical_frame::operator-(const physical_frame & other) const -> std::size_t { - return physical_frame_iterator::value_type{value.frame_number + index}; + return frame_number - other.frame_number; } } // namespace teachos::arch::memory::allocator -- cgit v1.2.3 From 30466aeb3da181c21bd451f32c1ff97e53a55dbc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matteo=20Gm=C3=BCr?= Date: Mon, 4 Nov 2024 13:29:03 +0000 Subject: Use more concepts and seperate iterator implementations --- .../src/memory/allocator/area_frame_allocator.cpp | 6 ++--- .../x86_64/src/memory/allocator/physical_frame.cpp | 27 ---------------------- 2 files changed, 3 insertions(+), 30 deletions(-) (limited to 'arch/x86_64/src/memory/allocator') 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 42aff68..3bc9676 100644 --- a/arch/x86_64/src/memory/allocator/area_frame_allocator.cpp +++ b/arch/x86_64/src/memory/allocator/area_frame_allocator.cpp @@ -24,16 +24,16 @@ namespace teachos::arch::memory::allocator { current_area = std::nullopt; auto next_area_with_free_frames = memory_areas | std::views::filter([this](auto const & area) { - auto address = area->base_address + area->area_length - 1; + auto address = area.base_address + area.area_length - 1; return physical_frame::containing_address(address) >= next_free_frame; }); auto const lowest_area_with_free_frames = std::ranges::min_element( - next_area_with_free_frames, [](auto const & a, auto const & b) { return a->base_address < b->base_address; }); + next_area_with_free_frames, [](auto const & a, auto const & b) { return a.base_address < b.base_address; }); if (lowest_area_with_free_frames != next_area_with_free_frames.end()) { - current_area = **lowest_area_with_free_frames; + current_area = *lowest_area_with_free_frames; // Update the `next_free_frame` according to the new memory area auto const start_frame = physical_frame::containing_address(current_area.value().base_address); if (next_free_frame < start_frame) diff --git a/arch/x86_64/src/memory/allocator/physical_frame.cpp b/arch/x86_64/src/memory/allocator/physical_frame.cpp index 63d84ec..ec387a1 100644 --- a/arch/x86_64/src/memory/allocator/physical_frame.cpp +++ b/arch/x86_64/src/memory/allocator/physical_frame.cpp @@ -21,31 +21,4 @@ namespace teachos::arch::memory::allocator ++frame_number; return *this; } - - auto physical_frame::operator+=(std::size_t operand) -> physical_frame & - { - frame_number += operand; - return *this; - } - - auto physical_frame::operator-=(std::size_t operand) -> physical_frame & - { - frame_number -= operand; - return *this; - } - - auto physical_frame::operator+(std::size_t operand) const -> physical_frame - { - return physical_frame{frame_number + operand}; - } - - auto physical_frame::operator-(std::size_t operand) const -> physical_frame - { - return physical_frame{frame_number - operand}; - } - - auto physical_frame::operator-(const physical_frame & other) const -> std::size_t - { - return frame_number - other.frame_number; - } } // namespace teachos::arch::memory::allocator -- cgit v1.2.3 From 1cd666241b59b800818812220e28b8b8572e4263 Mon Sep 17 00:00:00 2001 From: Felix Morgner Date: Tue, 19 Nov 2024 17:32:02 +0100 Subject: paging: de-templetize implementation --- arch/x86_64/src/memory/allocator/area_frame_allocator.cpp | 2 +- arch/x86_64/src/memory/allocator/tiny_frame_allocator.cpp | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) (limited to 'arch/x86_64/src/memory/allocator') 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 3bc9676..cb4fefa 100644 --- a/arch/x86_64/src/memory/allocator/area_frame_allocator.cpp +++ b/arch/x86_64/src/memory/allocator/area_frame_allocator.cpp @@ -81,5 +81,5 @@ namespace teachos::arch::memory::allocator return allocate_frame(); } - auto area_frame_allocator::deallocate_frame(physical_frame physical_frame) -> void { (void)physical_frame; } + auto area_frame_allocator::deallocate_frame(physical_frame const & physical_frame) -> void { (void)physical_frame; } } // namespace teachos::arch::memory::allocator diff --git a/arch/x86_64/src/memory/allocator/tiny_frame_allocator.cpp b/arch/x86_64/src/memory/allocator/tiny_frame_allocator.cpp index d37864e..ed000a0 100644 --- a/arch/x86_64/src/memory/allocator/tiny_frame_allocator.cpp +++ b/arch/x86_64/src/memory/allocator/tiny_frame_allocator.cpp @@ -4,7 +4,7 @@ namespace teachos::arch::memory::allocator { - tiny_frame_allocator::tiny_frame_allocator(area_frame_allocator & allocator) + tiny_frame_allocator::tiny_frame_allocator(frame_allocator & allocator) : frames{} { // Has to be done this way, because constructing the constructor with the data from allocator.allocate_frames(), @@ -34,7 +34,7 @@ namespace teachos::arch::memory::allocator return std::nullopt; } - auto tiny_frame_allocator::deallocate_frame(physical_frame physical_frame) -> void + auto tiny_frame_allocator::deallocate_frame(physical_frame const & physical_frame) -> void { for (auto & frame_option : frames) { -- cgit v1.2.3 From 4c44f822eefa743649693e0a49a978291925ddff Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matteo=20Gm=C3=BCr?= Date: Sun, 24 Nov 2024 09:17:53 +0000 Subject: Revert: de-templatize paging implementation --- .../x86_64/src/memory/allocator/tiny_frame_allocator.cpp | 16 ---------------- 1 file changed, 16 deletions(-) (limited to 'arch/x86_64/src/memory/allocator') diff --git a/arch/x86_64/src/memory/allocator/tiny_frame_allocator.cpp b/arch/x86_64/src/memory/allocator/tiny_frame_allocator.cpp index ed000a0..3cdf9c7 100644 --- a/arch/x86_64/src/memory/allocator/tiny_frame_allocator.cpp +++ b/arch/x86_64/src/memory/allocator/tiny_frame_allocator.cpp @@ -4,22 +4,6 @@ namespace teachos::arch::memory::allocator { - tiny_frame_allocator::tiny_frame_allocator(frame_allocator & allocator) - : frames{} - { - // Has to be done this way, because constructing the constructor with the data from allocator.allocate_frames(), - // does not work because it would set the value correctly but because we pass it as an std::optional it would not - // set the engaged flag. Meaning the has_value() method would still return false. - for (auto & frame : frames) - { - auto allocated = allocator.allocate_frame(); - if (allocated.has_value()) - { - frame.emplace(allocated.value()); - } - } - } - auto tiny_frame_allocator::allocate_frame() -> std::optional { for (auto & frame_option : frames) -- cgit v1.2.3