aboutsummaryrefslogtreecommitdiff
path: root/arch
diff options
context:
space:
mode:
authorMatteo Gmür <matteo.gmuer1@ost.ch>2025-05-30 12:48:57 +0000
committerMatteo Gmür <matteo.gmuer1@ost.ch>2025-05-30 12:48:57 +0000
commit9f2e780030e2101d5f7f01f42df805db9a5fa809 (patch)
treebfbcc9ce1c0a4235f15988a03274a14879e5bf73 /arch
parent3e597ede8079883b3b9d48faf94b8a7bec2a2118 (diff)
downloadteachos-9f2e780030e2101d5f7f01f42df805db9a5fa809.tar.xz
teachos-9f2e780030e2101d5f7f01f42df805db9a5fa809.zip
Clean up files
Diffstat (limited to 'arch')
-rw-r--r--arch/x86_64/CMakeLists.txt1
-rw-r--r--arch/x86_64/include/arch/memory/allocator/stack_frame_allocator.hpp67
-rw-r--r--arch/x86_64/scripts/kernel.ld6
-rw-r--r--arch/x86_64/src/memory/allocator/stack_frame_allocator.cpp105
4 files changed, 0 insertions, 179 deletions
diff --git a/arch/x86_64/CMakeLists.txt b/arch/x86_64/CMakeLists.txt
index 0a6ab9c..57b3a60 100644
--- a/arch/x86_64/CMakeLists.txt
+++ b/arch/x86_64/CMakeLists.txt
@@ -54,7 +54,6 @@ target_sources("_memory" PRIVATE
"src/memory/multiboot/elf_symbols_section.cpp"
"src/memory/multiboot/reader.cpp"
"src/memory/allocator/area_frame_allocator.cpp"
- "src/memory/allocator/stack_frame_allocator.cpp"
"src/memory/allocator/tiny_frame_allocator.cpp"
"src/memory/allocator/physical_frame.cpp"
"src/memory/paging/page_entry.cpp"
diff --git a/arch/x86_64/include/arch/memory/allocator/stack_frame_allocator.hpp b/arch/x86_64/include/arch/memory/allocator/stack_frame_allocator.hpp
deleted file mode 100644
index a8e7233..0000000
--- a/arch/x86_64/include/arch/memory/allocator/stack_frame_allocator.hpp
+++ /dev/null
@@ -1,67 +0,0 @@
-#ifndef TEACHOS_ARCH_X86_64_MEMORY_ALLOCATOR_STACK_FRAME_ALLOCATOR_HPP
-#define TEACHOS_ARCH_X86_64_MEMORY_ALLOCATOR_STACK_FRAME_ALLOCATOR_HPP
-
-#include "arch/memory/allocator/physical_frame.hpp"
-#include "arch/memory/multiboot/reader.hpp"
-#include "arch/stl/stack.hpp"
-
-#include <optional>
-
-namespace teachos::arch::memory::allocator
-{
- /**
- * @brief Uses an internal stack-like dynamic structure to keep track of the address of all avaialable physical frames
- * that are available using the memory areas read from the multiboot2 information pointer and simply pushes
- * deallocated frames back onto the stack. Allows for constant speed O(1) allocation and deallocation
- */
- struct stack_frame_allocator
- {
- /**
- * @brief Constructor
- *
- * @param mem_info Structure containg all relevant information to map and allocate memory
- */
- stack_frame_allocator(multiboot::memory_information const & mem_info);
-
- /**
- * @brief Allocate memory by finding and returning a free physical frame.
- *
- * @return next free physical frame or nullopt if none was found.
- */
- auto allocate_frame() -> std::optional<physical_frame>;
-
- /**
- * @brief Deallocates a previously allocated physical frame.
- *
- * @param physical_frame Previously allocated physical_frame that should be deallocated.
- */
- auto deallocate_frame(physical_frame const & physical_frame) -> void;
-
- private:
- /**
- * @brief Load all initally free physical frames from the current memory area into the underlying stack data
- * structure so they can simply be accessed once required. Recallling the method will load all free physical frames
- * from the next free memory area until there are no memory areas left.
- */
- auto load_free_physical_frames() -> void;
-
- /**
- * @brief Find the next memory area and write it into current_area.
- */
- auto choose_next_area() -> void;
-
- stl::stack<physical_frame> free_frames; ///< All currently free physical frames in a LIFO (last-in, first-out)
- ///< data structure.
- physical_frame next_free_frame; ///< The physical_frame after the last allocated one.
- std::optional<multiboot::memory_area> current_area; ///< The current memory area.
- multiboot::memory_area_container const
- memory_areas; ///< All memory areas in custom container allows to use std::ranges.
- 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::allocator
-
-#endif // TEACHOS_ARCH_X86_64_MEMORY_ALLOCATOR_STACK_FRAME_ALLOCATOR_HPP
diff --git a/arch/x86_64/scripts/kernel.ld b/arch/x86_64/scripts/kernel.ld
index df9d7e7..3d9a7ae 100644
--- a/arch/x86_64/scripts/kernel.ld
+++ b/arch/x86_64/scripts/kernel.ld
@@ -89,12 +89,6 @@ SECTIONS
{
*(.stl_text .stl_text*)
KEEP(*libstdc++.a:*(.text .text.*))
- KEEP(*libubsan.a:*(.text .text.*)) /* TODO: Include atomic_base into stl_text / Print where code lies: objdump -t build/bin/Debug/_kernel >> test.txt */
- KEEP(*liblsan.a:*(.text .text.*))
- KEEP(*libtsan.a:*(.text .text.*))
- KEEP(*libasan.a:*(.text .text.*))
- KEEP(*libgcc.a:*(.text .text.*))
- KEEP(*libatomic.a:*(.text .text.*))
}
.text ALIGN(4K) : AT(ADDR (.text))
diff --git a/arch/x86_64/src/memory/allocator/stack_frame_allocator.cpp b/arch/x86_64/src/memory/allocator/stack_frame_allocator.cpp
deleted file mode 100644
index 0fa277a..0000000
--- a/arch/x86_64/src/memory/allocator/stack_frame_allocator.cpp
+++ /dev/null
@@ -1,105 +0,0 @@
-#include "arch/memory/allocator/stack_frame_allocator.hpp"
-
-#include "arch/exception_handling/assert.hpp"
-
-#include <algorithm>
-#include <array>
-#include <ranges>
-
-namespace teachos::arch::memory::allocator
-{
- stack_frame_allocator::stack_frame_allocator(multiboot::memory_information const & mem_info)
- : free_frames()
- , next_free_frame()
- , current_area(std::nullopt)
- , 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))
- , multiboot_end(physical_frame::containing_address(mem_info.multiboot_end))
- {
- load_free_physical_frames();
- }
-
- auto stack_frame_allocator::load_free_physical_frames() -> void
- {
- choose_next_area();
- if (!current_area.has_value())
- {
- return;
- }
-
- auto const address = current_area.value().base_address + current_area.value().area_length - 1;
- physical_frame const current_area_last_frame = physical_frame::containing_address(address);
-
- // Only try to allocate memory if current_area is not null, because
- // the current_area is null if there is no more available memory.
- while (next_free_frame <= current_area_last_frame)
- {
- 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;
- // TODO: Fix using heap like structure to initalize paging allocator used by heap does not work
- // free_frames.push(next_free_frame);
- static uint32_t count = 0U;
- count++;
- }
- }
- }
-
- auto stack_frame_allocator::choose_next_area() -> void
- {
- 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;
- 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; });
-
- 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
- auto const start_frame = physical_frame::containing_address(current_area.value().base_address);
- if (next_free_frame < start_frame)
- {
- next_free_frame = start_frame;
- }
- }
- }
-
- auto stack_frame_allocator::allocate_frame() -> std::optional<physical_frame>
- {
- // If the underlying stack is empty that are no free frames left to allocate.
- if (free_frames.empty())
- {
- load_free_physical_frames();
- if (free_frames.empty())
- {
- return std::nullopt;
- }
- }
-
- decltype(auto) top = free_frames.top();
- free_frames.pop();
- return top;
- }
-
- auto stack_frame_allocator::deallocate_frame(physical_frame const & physical_frame) -> void
- {
- free_frames.push(physical_frame);
- }
-} // namespace teachos::arch::memory::allocator