aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMatteo Gmür <matteo.gmuer1@ost.ch>2024-10-02 13:02:35 +0000
committerMatteo Gmür <matteo.gmuer1@ost.ch>2024-10-02 13:02:35 +0000
commit32add45849744dc976c7af6ec24f985bbace47d3 (patch)
tree0f4e31827bf81e7489f541e0e7ff8eb87df34d95
parent4c60bad3150b07e973eb385613a90ebb8c94ecac (diff)
downloadteachos-32add45849744dc976c7af6ec24f985bbace47d3.tar.xz
teachos-32add45849744dc976c7af6ec24f985bbace47d3.zip
Creating base frame allocation code
-rw-r--r--arch/x86_64/include/arch/kernel/main.hpp2
-rw-r--r--arch/x86_64/include/arch/memory/frame_allocator.hpp48
-rw-r--r--arch/x86_64/src/kernel/main.cpp6
-rw-r--r--arch/x86_64/src/memory/frame_allocator.cpp9
4 files changed, 63 insertions, 2 deletions
diff --git a/arch/x86_64/include/arch/kernel/main.hpp b/arch/x86_64/include/arch/kernel/main.hpp
index 6759eb2..8813b46 100644
--- a/arch/x86_64/include/arch/kernel/main.hpp
+++ b/arch/x86_64/include/arch/kernel/main.hpp
@@ -1,8 +1,6 @@
#ifndef TEACHOS_ARCH_X86_64_KERNEL_MAIN_HPP
#define TEACHOS_ARCH_X86_64_KERNEL_MAIN_HPP
-#include <cstddef>
-
namespace teachos::arch::kernel
{
auto main() -> void;
diff --git a/arch/x86_64/include/arch/memory/frame_allocator.hpp b/arch/x86_64/include/arch/memory/frame_allocator.hpp
new file mode 100644
index 0000000..bcb0882
--- /dev/null
+++ b/arch/x86_64/include/arch/memory/frame_allocator.hpp
@@ -0,0 +1,48 @@
+#ifndef TEACHOS_ARCH_X86_64_MEMORY_FRAME_HPP
+#define TEACHOS_ARCH_X86_64_MEMORY_FRAME_HPP
+
+#include <cstddef>
+#include <optional>
+
+namespace teachos::arch::memory
+{
+ namespace
+ {
+ const size_t PAGE_FRAME_SIZE = 4096U;
+ }
+
+ struct Frame
+ {
+ size_t frame_number;
+
+ Frame(size_t frame_number)
+ : frame_number(frame_number)
+ {
+ // Nothing to do
+ }
+
+ auto containing_address(size_t address) -> Frame { return Frame{address / PAGE_FRAME_SIZE}; }
+ };
+
+ struct IFrameAllocator
+ {
+ virtual auto allocate_frame() -> std::optional<Frame> = 0;
+ virtual auto deallocate_frame(Frame frame) -> void = 0;
+ };
+
+ struct AreaFrameAllocator : public IFrameAllocator
+ {
+ Frame next_free_frame;
+ // std::optional<MemoryArea> current_area;
+ // MemoryArea * areas;
+ Frame kernel_start;
+ Frame kernel_end;
+ Frame multiboot_start;
+ Frame multiboot_end;
+
+ auto allocate_frame() -> std::optional<Frame> override;
+ auto deallocate_frame(Frame frame) -> void override;
+ };
+} // namespace teachos::arch::memory
+
+#endif // TEACHOS_ARCH_X86_64_MEMORY_FRAME_HPP
diff --git a/arch/x86_64/src/kernel/main.cpp b/arch/x86_64/src/kernel/main.cpp
index 4deac6d..da496a6 100644
--- a/arch/x86_64/src/kernel/main.cpp
+++ b/arch/x86_64/src/kernel/main.cpp
@@ -125,6 +125,12 @@ namespace teachos::arch::kernel
multiboot_info * multiboot_information_pointer = (multiboot_info *)arch::boot::multiboot_information_pointer;
auto multiboot_tag = &(multiboot_information_pointer->tags);
+ text::write("Multiboot Start: ", text::common_attributes::green_on_black);
+ text::write_number(arch::boot::multiboot_information_pointer, text::common_attributes::green_on_black);
+ text::write("Multiboot End: ", text::common_attributes::green_on_black);
+ text::write_number(arch::boot::multiboot_information_pointer + multiboot_information_pointer->total_size,
+ text::common_attributes::green_on_black);
+
/*
* Loop over the multiboot2 tags to access the information needed.
* Tags are defined in the header file and are padded so that each
diff --git a/arch/x86_64/src/memory/frame_allocator.cpp b/arch/x86_64/src/memory/frame_allocator.cpp
new file mode 100644
index 0000000..425528a
--- /dev/null
+++ b/arch/x86_64/src/memory/frame_allocator.cpp
@@ -0,0 +1,9 @@
+#include "arch/memory/frame_allocator.hpp"
+
+namespace teachos::arch::memory
+{
+ auto AreaFrameAllocator::allocate_frame() -> std::optional<Frame> {}
+
+ auto AreaFrameAllocator::deallocate_frame(Frame frame) -> void {}
+
+} // namespace teachos::arch::memory