aboutsummaryrefslogtreecommitdiff
path: root/arch/x86_64/src
diff options
context:
space:
mode:
authorMatteo Gmür <matteo.gmuer1@ost.ch>2024-10-29 09:31:36 +0000
committerMatteo Gmür <matteo.gmuer1@ost.ch>2024-10-29 09:31:36 +0000
commitdfb0ea2fd7525dd12addf295aef4d642e93ea22a (patch)
tree61b4c765816581833b9472680c3b64288b8d0951 /arch/x86_64/src
parent4e9338075cf30702b922e5aecbc33c18bfd3f759 (diff)
downloadteachos-dfb0ea2fd7525dd12addf295aef4d642e93ea22a.tar.xz
teachos-dfb0ea2fd7525dd12addf295aef4d642e93ea22a.zip
Create tiny frame allocator which holds only 3 frames
Diffstat (limited to 'arch/x86_64/src')
-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