aboutsummaryrefslogtreecommitdiff
path: root/arch/x86_64/include
diff options
context:
space:
mode:
Diffstat (limited to 'arch/x86_64/include')
-rw-r--r--arch/x86_64/include/arch/kernel/main.hpp2
-rw-r--r--arch/x86_64/include/arch/memory/frame_allocator.hpp48
2 files changed, 48 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