aboutsummaryrefslogtreecommitdiff
path: root/arch/x86_64/src/memory
diff options
context:
space:
mode:
Diffstat (limited to 'arch/x86_64/src/memory')
-rw-r--r--arch/x86_64/src/memory/allocator/tiny_frame_allocator.cpp34
1 files changed, 34 insertions, 0 deletions
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<physical_frame>
+ {
+ 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