From db8a61a779cd3192b451931ce8b41bd41d73f91a Mon Sep 17 00:00:00 2001 From: Alex Kotov Date: Wed, 25 Nov 2020 17:03:33 +0500 Subject: [PATCH] Remove page frame allocator --- kernelmq/Makefile | 1 - kernelmq/init.c | 3 -- kernelmq/pfa.c | 111 ---------------------------------------------- kernelmq/pfa.h | 14 ------ 4 files changed, 129 deletions(-) delete mode 100644 kernelmq/pfa.c delete mode 100644 kernelmq/pfa.h diff --git a/kernelmq/Makefile b/kernelmq/Makefile index 33db017..4666384 100644 --- a/kernelmq/Makefile +++ b/kernelmq/Makefile @@ -14,7 +14,6 @@ OBJS += main.c.o OBJS += init.c.o OBJS += multiboot.c.o OBJS += panic.c.o panic.asm.cpp.o -OBJS += pfa.c.o OBJS += paging.c.o paging.asm.cpp.o OBJS += pagedir.c.o diff --git a/kernelmq/init.c b/kernelmq/init.c index 8d0463c..5abdde3 100644 --- a/kernelmq/init.c +++ b/kernelmq/init.c @@ -1,5 +1,4 @@ #include "panic.h" -#include "pfa.h" #include "protected.h" #include "paging.h" @@ -19,8 +18,6 @@ void init(const struct KernelMQ_Info *const kinfo_ptr) assert(kernelmq_info_validate_and_copy(&kinfo, kinfo_ptr), "Invalid kernel information."); - pfa_initialize(&kinfo); - protected_initialize(&kinfo); // Set up a new post-relocate bootstrap pagetable so that diff --git a/kernelmq/pfa.c b/kernelmq/pfa.c deleted file mode 100644 index d9c74c1..0000000 --- a/kernelmq/pfa.c +++ /dev/null @@ -1,111 +0,0 @@ -#include "pfa.h" - -#include "config.h" -#include "panic.h" -#include "logger.h" - -#include "stdlib.h" - -#define FRAMES_COUNT (PAGE_DIR_LENGTH * PAGE_TABLE_LENGTH) - -static unsigned char frames[FRAMES_COUNT]; - -static void mark_used(unsigned long base, unsigned long limit); - -void pfa_initialize(const struct KernelMQ_Info *const kinfo) -{ - logger_info_from("pfa", "Initialize page frame allocator."); - - kmemset(frames, 0, sizeof(frames)); - - mark_used(0, MEM_UPPER_BASE - 1); - - mark_used(kinfo->kernel_phys_base, kinfo->kernel_phys_limit); - - for (unsigned int i = 0; i < kinfo->modules_count; ++i) { - const struct KernelMQ_Info_Module *const module = &kinfo->modules[i]; - - mark_used(module->base, module->limit); - } - - for (unsigned int i = 0; i < kinfo->areas_count; ++i) { - const struct KernelMQ_Info_Area *const area = &kinfo->areas[i]; - - if (!area->is_available) { - mark_used(area->base, area->limit); - } - } -} - -unsigned long pfa_alloc_page() -{ - for (unsigned int i = 0; i < FRAMES_COUNT; ++i) { - if (!frames[i]) { - frames[i] = 0xFF; - return i * PAGE_SIZE; - } - } - - return 0; -} - -unsigned long pfa_alloc_big_page() -{ - unsigned int start = 0; - - for (unsigned int i = 0; i < FRAMES_COUNT; ++i) { - if (frames[i]) { - start = i + 1; - continue; - } - - if (start % (PAGE_BIG_SIZE / PAGE_SIZE)) { - continue; - } - - if (i - start + 1 == PAGE_BIG_SIZE / PAGE_SIZE) { - for (unsigned int j = start; j <= i; ++j) { - frames[j] = 0xFF; - } - - return start * PAGE_SIZE; - } - } - - return 0; -} - -void pfa_free_page(const unsigned long base) -{ - assert(!(base % PAGE_SIZE), "Small page address to free is not aligned."); - - const unsigned long i = base / PAGE_SIZE; - - if (i >= FRAMES_COUNT) { - return; - } - - frames[i] = 0; -} - -void pfa_free_big_page(const unsigned long base) -{ - assert(!(base % PAGE_BIG_SIZE), "Big page address to free is not aligned."); - - const unsigned long start = base / PAGE_SIZE; - const unsigned long end = start + PAGE_BIG_SIZE / PAGE_SIZE; - - for (unsigned int i = start; i <= end && i < FRAMES_COUNT; ++i) { - frames[i] = 0; - } -} - -void mark_used(const unsigned long base, const unsigned long limit) -{ - const unsigned int start = base / PAGE_SIZE; - const unsigned int end = limit / PAGE_SIZE; - - for (unsigned int i = start; i <= end; ++i) { - frames[i] = 0xFF; - } -} diff --git a/kernelmq/pfa.h b/kernelmq/pfa.h deleted file mode 100644 index 70526b3..0000000 --- a/kernelmq/pfa.h +++ /dev/null @@ -1,14 +0,0 @@ -#ifndef KERNELMQ_INCLUDED_PFA -#define KERNELMQ_INCLUDED_PFA 1 - -#include "info.h" - -void pfa_initialize(const struct KernelMQ_Info *kinfo); - -unsigned long pfa_alloc_page(); -unsigned long pfa_alloc_big_page(); - -void pfa_free_page(unsigned long base); -void pfa_free_big_page(unsigned long base); - -#endif