From 55f32173e97fdcf4a45006b66cc4b20329a5c7af Mon Sep 17 00:00:00 2001 From: Fabian Imhof Date: Sun, 24 Nov 2024 13:10:21 +0000 Subject: implement basic heap and remap it --- arch/x86_64/include/arch/memory/heap/allocator.hpp | 32 ++++++++++++++++++++++ arch/x86_64/include/arch/memory/heap/concept.hpp | 15 ++++++++++ arch/x86_64/include/arch/memory/main.hpp | 13 +++++++++ .../arch/memory/paging/active_page_table.hpp | 2 +- 4 files changed, 61 insertions(+), 1 deletion(-) create mode 100644 arch/x86_64/include/arch/memory/heap/allocator.hpp create mode 100644 arch/x86_64/include/arch/memory/heap/concept.hpp create mode 100644 arch/x86_64/include/arch/memory/main.hpp (limited to 'arch/x86_64/include') diff --git a/arch/x86_64/include/arch/memory/heap/allocator.hpp b/arch/x86_64/include/arch/memory/heap/allocator.hpp new file mode 100644 index 0000000..c486a4c --- /dev/null +++ b/arch/x86_64/include/arch/memory/heap/allocator.hpp @@ -0,0 +1,32 @@ +#ifndef TEACHOS_ARCH_X86_64_MEMORY_HEAP_ALLOCATOR_HPP +#define TEACHOS_ARCH_X86_64_MEMORY_HEAP_ALLOCATOR_HPP + +#include + +namespace teachos::arch::memory::heap +{ + std::size_t constexpr HEAP_START = 0x4000'0000; + std::size_t constexpr HEAP_SIZE = 100 * 1024; + + struct bump_allocator + { + bump_allocator(std::size_t heap_start, std::size_t heap_end) + : heap_start{heap_start} + , heap_end{heap_end} + , next{heap_start} + { + } + + auto allocate(std::size_t size) -> void *; + + auto deallocate(uint8_t * pointer, std::size_t size) -> void; + + private: + std::size_t heap_start; + std::size_t heap_end; + std::size_t next; + }; + +} // namespace teachos::arch::memory::heap + +#endif \ No newline at end of file diff --git a/arch/x86_64/include/arch/memory/heap/concept.hpp b/arch/x86_64/include/arch/memory/heap/concept.hpp new file mode 100644 index 0000000..a525b0b --- /dev/null +++ b/arch/x86_64/include/arch/memory/heap/concept.hpp @@ -0,0 +1,15 @@ +#ifndef TEACHOS_ARCH_X86_64_MEMORY_HEAP_CONCEPT_HPP +#define TEACHOS_ARCH_X86_64_MEMORY_HEAP_CONCEPT_HPP + +#include + +namespace teachos::arch::memory::heap +{ + template + concept HeapAllocator = requires(T t, uint8_t * pointer, std::size_t size) { + { t.allocate(size) } -> std::same_as; + { t.deallocate(pointer, size) } -> std::same_as; + }; +} // namespace teachos::arch::memory::heap + +#endif // TEACHOS_ARCH_X86_64_MEMORY_HEAP_CONCEPT_HPP \ No newline at end of file diff --git a/arch/x86_64/include/arch/memory/main.hpp b/arch/x86_64/include/arch/memory/main.hpp new file mode 100644 index 0000000..e166285 --- /dev/null +++ b/arch/x86_64/include/arch/memory/main.hpp @@ -0,0 +1,13 @@ +#ifndef TEACHOS_ARCH_X86_64_MEMORY_MAIN_HPP +#define TEACHOS_ARCH_X86_64_MEMORY_MAIN_HPP + +namespace teachos::arch::memory +{ + /** + * @brief + * + */ + auto initialize_memory_management() -> void; +} // namespace teachos::arch::memory + +#endif diff --git a/arch/x86_64/include/arch/memory/paging/active_page_table.hpp b/arch/x86_64/include/arch/memory/paging/active_page_table.hpp index 4687209..1b2aaed 100644 --- a/arch/x86_64/include/arch/memory/paging/active_page_table.hpp +++ b/arch/x86_64/include/arch/memory/paging/active_page_table.hpp @@ -98,7 +98,7 @@ namespace teachos::arch::memory::paging * @see map_page_to_frame */ template - auto map_next_free_page_to_frame(T & allocator, virtual_page page, std::bitset<64U> flags) -> void + auto map_page_to_next_free_frame(T & allocator, virtual_page page, std::bitset<64U> flags) -> void { auto const frame = allocator.allocate_frame(); exception_handling::assert(frame.has_value(), "[Page mapper] Out of memory exception"); -- cgit v1.2.3